我試圖佈局使用GridLayout
一種Android屏幕的Android網格佈局橫向填充,這裏是一個模擬的佈局展示什麼,我試圖完成:動態片段
我翻譯的是樣機成佈局和這裏的結果在模擬器中運行:
我要在中央的黑色部分使用盡可能多的水平空間possibl e,如在模擬佈局中。但正如你所看到的,右邊的白色組件正在使用所有可用的水平空間。
我得到在日誌中這樣的錯誤:
01-06 08:27:38.045: D/android.widget.GridLayout(7745): horizontal constraints: x2-x0>=71, x1-x0>=64, x2-x1>=128, x3-x2>=1280, x3-x0<=1280 are inconsistent; permanently removing: x3-x0<=1280.
我使用2個FrameLayout
組件的佔位符動態加載片段。例如,取決於在紅色面板中單擊哪個按鈕,將不同的片段加載到黑色面板中。我看到的另一個相關問題是黑色面板會根據加載的片段中有多少個按鈕來改變大小。
如果可能,我寧願使用GridLayout
,但也許我想用GridLayout做什麼是不可能的?我嘗試使用線性和相對佈局來處理此佈局,但無法正確使用。
這是我的佈局文件:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="3">
<FrameLayout
android:id="@+id/category_placeholder"
android:layout_column="0"
android:layout_gravity="fill_vertical"
android:background="#0f0"
android:gravity="start"
/>
<FrameLayout
android:id="@+id/menu_item_placeholder"
android:layout_column="1"
android:layout_gravity="fill_horizontal|fill_vertical"
android:background="#00f"
android:gravity="start"
/>
<fragment
android:id="@+id/cart"
android:layout_column="2"
android:layout_gravity="fill_vertical"
android:layout_rowSpan="2"
class="com.example.splitscreen.OrderFragment"
android:background="#4b0082"
android:gravity="end" />
<TextView
android:id="@+id/xxx"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_gravity="fill_horizontal"
android:layout_row="1"
android:background="#0f0"
android:gravity="center"
android:padding="25dp"
android:text="xxx"
android:textColor="#0f0" >
</TextView>
</GridLayout>
如果你不需要白色內容,爲什麼你有'columnCount = 3'? –