2015-10-05 54 views
0

当我指定的发言权和image view之间的weight且所包含相同linear layout我应该可以在layout_width值设置为内linear layout指定layout_width?它似乎不应该被设置,因为我说我想要其他layout占用90%的空间,而image view占用10%的空间。Android的 - 使用layout_weight时

而且好像我可以设置image view有10%的空间和layout有90%的空间,但我仍然可以指定image viewdp's值?

在这种情况下,我应该只设置在dp's值的image,然后指定的1为其他layout一个weight

感谢

+0

请发表你试过到目前为止。 – Tauqir

+0

好吧,我已经尝试了几个不同的东西,它们在模拟器中看起来很好,所以我在问什么是使用权重时指定layout_width的正确权重,以及如果可以使用layout_weight,然后将layout_width值设置为DP的? – berimbolo

+1

将宽度设置为0dp。 – StG

回答

1

在这种情况下,你layout_width应该是0dp。如果将重量参数定义为0dp以外的其他宽度,您还将得到一个皮棉警告。

refer this了解更多详情。

+0

好的,谢谢Rahul,你能不能更新一下,当指定图像的宽度为150dp时,是否应该使用布局权重,如果其他视图包含指定其重量为1,填补其余的空间或应该是match_parent? – berimbolo

+0

[请参阅本文](http://developer.android.com/guide/topics/ui/layout/linear.html)了解详情。阅读完之后你会知道重量是如何工作的。 –

1

在布局中使用重量时。 你会想要做到这一点。

父布局将使用值为10的weightSum=10,但它可以是我们想要的任何值。 为儿童布局。都应该是layout_width="fill_parent"然后你就可以设置layout_weight="2"为孩子之一,然后layout_weight="8"为其他孩子

像这样

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:weightSum="10"> 


<imageView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="8" 
    /> 

<LinearLayoout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="2" />