答案 0 :(得分:1)
如果您使用水平LinearLayout
的{{1}}窗口小部件,并且其中一个子窗口想要占用所有可用的水平空间,那么您应该使用布局权重。
对于第一个orientation
集:
TextView
对于第二个layout_width="0dp"
layout_weight="1"
:
TextView
在这种情况下,您说第二个layout_width="wrap_content"
将占用所需的水平空间,第一个TextView
将采用其余的。 " 0dp"只是一个优化,以防止额外的布局测量调用。
答案 1 :(得分:1)
这样做:
<LinearLayout
android:width="match_parent"
android:height="wrap_content"
android:orientation="horizontal">
<!-- the text -->
<TextView
android:width="0dp"
android:height="wrap_content"
android:weight="1"/>
<!-- the time -->
<TextView
android:width="match_parent"
android:height="wrap_content"/>
</LinearLayout>
或者这个:
<LinearLayout
android:width="match_parent"
android:height="wrap_content"
android:orientation="horizontal">
<!-- the text -->
<TextView
android:width="match_parent"
android:height="wrap_content"
android:maxWidth="300dp"/> <!-- can be a different dimention -->
<!-- the time -->
<TextView
android:width="match_parent"
android:height="wrap_content"/>
</LinearLayout>