在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