我設定了一個視頻展示,當按下附加的影像按鈕時播放特定的視頻。但是,我在縱向和橫向模式方面遇到了一些問題。
為了解決這個問題,我在這里關注了幾個執行緒并創建了一個帶有 layout.xml 的“layout-land”檔案夾,然后從 activity_main.xml 檔案中復制粘貼所有內容。
但是,傾斜手機或平板電腦時,我仍然無法讓應用程式識別和使用土地布局,我唯一的錯誤是:
"layout-land 中的布局 "layout" 在基本
layout檔案夾中沒有宣告;當在與此限定符不匹配的配置中查詢資源時,這可能會導致崩潰"*
到目前為止,我已經嘗試過:在 XML 文本上使用 Ctrl C 和 Ctrl V。gradle 同步、快取無效、app pc 重啟和更改 XML 檔案 ID 以匹配。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@ id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageButton
android:id="@ id/imageButton1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginEnd="520dp"
android:onClick="Click1"
android:src="@drawable/placeholder1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck"
tools:srcCompat="@tools:sample/avatars" />
<ImageButton
android:id="@ id/imageButton2"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginEnd="170dp"
android:onClick="Click2"
android:src="@drawable/placeholder2"
app:layout_constraintBottom_toBottomOf="@ id/videoView1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck"
tools:srcCompat="@tools:sample/avatars" />
<ImageButton
android:id="@ id/imageButton3"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="170dp"
android:onClick="Click3"
android:src="@drawable/placeholder3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck"
tools:srcCompat="@tools:sample/avatars" />
<ImageButton
android:id="@ id/imageButton4"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="520dp"
android:onClick="Click4"
android:src="@drawable/placeholder4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="SpeakableTextPresentCheck"
tools:srcCompat="@tools:sample/avatars" />
<VideoView
android:id="@ id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
PS。如何在我的代碼片段中獲得正確的顏色?我第一次使用它。
uj5u.com熱心網友回復:
@Mike M 評論的所有學??分。
Landscape.xml檔案的名稱必須與原始activity_main.xml檔案的名稱相同,傾斜才能正常作業。重命名時只需忽略 Android Studio 的警告和投訴即可。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/506984.html
