2010-10-07 55 views
3

在Android设计布局一段时间后,我仍然无法得到它的挂钩。通常结果是不可预测的。Android UI:什么样的布局选项是互斥的?

我认为这部分归结为一些布局选项不能很好地协同工作。即如果您正在使用一种指定布局的方式,则无意使用其他方式。

值得注意的是,对我而言,将layout_widthfill_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有任何影响。我可能会去实验并禁用一些其他的东西来看看它给了我什么。但我的问题在于:是否有任何人(逻辑)信息关于哪个属性阻止或反直觉影响谁?我想要一劳永逸地排序。这是记录在某处吗?

回答

2

我注意到layout_weight似乎呈现minWidth无用。

给定三个线性布局按钮,左右权重为0,中心为1,改变其中任何一个的最小宽度对渲染视图的方式都没有影响,直到我为每个按钮完全删除layout_weight属性。我甚至确保所有minWidths的总和小于总视图的宽度。

我不知道为什么是这种情况。该documentation关于layout_weight:

该属性指定的“重要性” 值到一个视图,并允许它 ,以填补剩余的空间 父视图扩展。子视图可以 指定一个整数权重值,然后 视图 组中的任何剩余空间分配给孩子们在他们宣称的重量的比例

我也真的很想了解其他布局参数相互冲突。对我来说,为视图定义权重以填充“父视图中的剩余空间”完全忽略视图的最小宽度设置似乎非常不直观。

+0

谢谢。和你一样,我希望得到更多答案。我会把这个开放一段时间。 – pjv 2011-01-30 15:42:59