什么是0dip layout_height或layouth_width的把戏?
问题描述:
我的意思是,为什么有人要他们认为是0dip高度? 我见过很多次,一定是有什么把戏,但我不明白这一点。
I mean why anybody want they view to be 0dip height ? I have seen this many times, there must be some kind of trick, but I do not get it.
<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>
为什么他们没有如WRAP_CONTENT使用?他们怎么想达到什么目的?
Why they don't use for example wrap_content ? what do they want to achieve ?
答
这是通常具有的LinearLayout里面很多观点时使用,并且已经设置的android:layout_weight =1,以这两种观点采取平等的空间。例如:
This is usually used when having many views inside a linearlayout and have set android:layout_weight="1" in order both views to take equal space. for example:
<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>
在这种情况下,显示将需要多达高度,因为所有的其它视图。
In that case, the view will take as much height as all other views.