這真是令人沮喪。我試圖想出一種佈局認可的方式,在縱向時沿水平方向重新定位按鈕的工具欄,而在橫向時則沿垂直方向沿着右側方向。例如取決於方向,我想要一排行動按鈕。Android佈局<include>,它支持定位佈局xml文件嗎? - 陸地工作呢?
首先,我不想在layout-land版本中複製所有activity_main.xml佈局內容,所以我嘗試使用該元素指向toolbar.xml佈局和layout-land版本。
/res
/layout
/activity_main.xml
/toolbar.xml
/layout-land
/toolbar.xml
activity_main.xml中:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
...
<include android:id="@+id/toolbar" layout="@layout/toolbar"/>
...
toolbar.xml:
<ToggleButton
android:id="@+id/serviceToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:text="Port!" />
...
佈局,土地/ toolbar.xml:
<ToggleButton
android:id="@+id/serviceToggleButton"
android:layout_width="64dip"
android:layout_height="64dip"
android:layout_marginRight="10dip"
android:text="Land!" />
...
不工作。當平板電腦的方向發生變化時,我會看到相同的按鈕文本「端口!」和「Land!」按鈕文本從不出現。例如我改變了按鈕文本,以防我的LinearLayout屬性沒有像我期望的那樣對齊。
SO!我試着用所有描述主佈局xml文件的land/port示例,並且使用了垃圾。我創建了一個activity_main.xml的佈局 - 土地副本,並調整了佈局以使我預期它將出現在橫向中。 (我也刪除了)
/res
/layout
/activity_main.xml
/layout-land
/activity_main.xml
不起作用。我現在有一個乾淨的縱向和橫向activity_main.xml,它們有明顯的差異,當我的方向改變時不會出現。
什麼給?任何人有任何建議?順便說一句,在這種情況下,我堅持與Android 2.3.4。提前致謝!
你在AndroidManifest.xml文件中的configChanges標誌嗎? – Blackbelt
我在我的AndroidManifest.xml中有 MainActivity的android:configChanges =「orientation | keyboardHidden」>。那應該沒問題吧? –
garlicman
不,它不是。如果你想使用佈局土地,你必須刪除這些標誌 – Blackbelt