如何在一行中放置TextView,第二个TextView应该占据屏幕的第三部分?
问题描述:
我有以下布局:如何在一行中放置TextView,第二个TextView应该占据屏幕的第三部分?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="@+id/movie_icon"
android:src="@drawable/star_off"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<TextView android:id="@+id/name"
android:textSize="16sp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="left"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:text="aaaaa"/>
<TextView android:id="@+id/time"
android:textSize="16sp"
android:text="1:25 - 2:25"
android:layout_height="74dip"
android:layout_width="fill_parent"
android:gravity="right"
android:layout_weight="2"
android:background="@drawable/time_background"/>
</LinearLayout>
time
和name
TextViews具有相同的宽度,但我需要的time
宽度等于name
半宽度。我该怎么做?或者,如何创建name
宽度固定(例如,100dip)?
答
试着将它们的宽度设置为0,并将weight =“1”设置为您想要的更小,对于您想要的更大的设置weight =“2”。如果这不符合你的要求,我不确定有没有办法像你提到的那样为它设置像100dip这样的固定宽度。
'layout_width'不能为零,它必须被定义(如果我没有定义它,它显示正确,但是当运行返回应用程序错误时)。那么如何遵循第二种方法呢? – 2011-05-21 12:21:30