在Android設計佈局一段時間後,我仍然無法得到它的掛鉤。通常結果是不可預測的。Android UI:什麼樣的佈局選項是互斥的?
我認爲這部分歸結爲一些佈局選項不能很好地協同工作。即如果您正在使用一種指定佈局的方式,則無意使用其他方式。
值得注意的是,對我而言,將layout_width
從fill_parent
更改爲wrap_content
通常會改變世界。讓我給你一個具體的例子:
我的活動佈局的一部分,是一個的LinearLayout:
<LinearLayout android:id="@+id/ll2" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<LinearLayout android:id="@+id/ll2a" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1">
<TextView android:id="@+id/l_cover" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/book_item_l_cover">
</TextView>
<ImageButton android:id="@+id/i_cover"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scaleType="centerInside" android:gravity="center"
android:layout_weight="1" android:adjustViewBounds="true"
android:src="@drawable/spinner_black_76" android:minWidth="400dip">
</ImageButton>
</LinearLayout>
<LinearLayout android:id="@+id/ll2b" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="1">
<TextView android:id="@+id/l_back_cover" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/book_item_l_back_cover">
</TextView>
<ImageButton android:id="@+id/i_back_cover"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scaleType="centerInside" android:gravity="center"
android:layout_weight="1" android:adjustViewBounds="true"
android:src="@drawable/spinner_black_76">
</ImageButton>
</LinearLayout>
</LinearLayout>
爲了獲得左對齊標籤的按鈕組合旁邊的海誓山盟2列,我不得不使用layout_weight
屬性。由於adjustViewBounds
屬性,ImageButton縮小圖像周圍。這給我一個很好的結果。
現在我最終還想要的是讓按鈕具有一定的最小尺寸,這樣即使手指不包含任何圖像(它們會縮小到僅僅幾毫米),手指仍然可以輕鬆按下它們。正如你所看到的,我嘗試了設置android:minWidth="400dip"
。我預計這個按鈕可以填滿整個屏幕寬度的一半(400是一個相當大的值),但我沒有看到任何區別。
我想上面的其他屬性之一是防止minWidth
有任何影響。我可能會去實驗並禁用一些其他的東西來看看它給了我什麼。但我的問題在於:是否有任何人(邏輯)信息關於哪個屬性阻止或反直覺影響誰?我想要一勞永逸地排序。這是記錄在某處嗎?
謝謝。和你一樣,我希望得到更多答案。我會把這個開放一段時間。 – pjv 2011-01-30 15:42:59