Luk*_*kap 17 height layout android
我的意思是为什么有人希望他们认为是0dip高度?我已经看过很多次,必须有某种技巧,但我不明白.
<TextView android:gravity="top" android:textColor="#FFFF0000"
android:textSize="20dip" android:text="TextView"
android:layout_height="0dip" android:layout_width="fill_parent"
android:id="@+id/contactName"></TextView>
Run Code Online (Sandbox Code Playgroud)
他们为什么不使用例如wrap_content?他们想要实现什么?
ina*_*ruk 25
这大量用于视图LinearLayout.有三个"布局"属性LinearLayout可以识别:
android:layout_heightandroid:layout_widthandroid:layout_weight您可以android:layout_weight在教程项目中找到示例.
因此,当android:layout_weight在ViewX 上使用并且LinearLayout是水平的时,则android:layout_width简单地忽略X.
类似地,当android:layout_weight在ViewX 上使用并且LinearLayout是垂直的时,则android:layout_height忽略X' .
这实际上意味着,你可以把任何东西在那些忽略的字段:0dp或fill_parent或wrap_content.没关系.但是建议使用0dp这样View的,不要额外计算它们的高度或宽度(然后忽略它).这个小技巧简单地节省了CPU周期.
Dim*_*ris 18
这通常用于在linearlayout中有很多视图并且设置android:layout_weight ="1"以便两个视图占用相等的空间.例如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,视图将采用与所有其他视图一样多的高度.
| 归档时间: |
|
| 查看次数: |
14858 次 |
| 最近记录: |