是否有可能告诉一个视图,它应该至少包装它的内容,但如果父视图留下空间拉伸,它应该填充它的父视图?
的例子:
我想要的是,容器的线性布局围绕它的内容…在这种情况下,我的标题文本视图比滚动视图更宽,它不会被切断!如果我将标题textview设置为wrap_content,如果scrollview比标题更宽,它不会填充它的父元素…
<LinearLayout
android:id="@+id/llWeightsParent"
style="@style/group"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:clickable="true"
android:onClick="onClick"
android:orientation="vertical" >
<TextView
android:id="@+id/tvWeight"
style="@style/text_group_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:text="@string/weight" />
<ScrollView
android:id="@+id/svWeights"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/llWeights"
style="@style/group_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
如果你指的是imageview,那么你可以设置
android:layout_width="match_parent"
android:scaleType="centerInside"
对于其他人,我只设置android:layout_width="match_parent"
,不会担心太多。