设置LinearLayout的最大宽度

Asa*_*ahi 8 layout user-interface android

如何设置水平的最大宽度LinearLayout?因此,如果内容很短(比如某些文本),则布局会缩小,如果内容较长,则不会扩展超过某个最大宽度值.

我更喜欢在XML级别这样做.

Asa*_*ahi 7

这样做 - 除了之前的答案中建议的我需要的是添加另一个布局(@+id/TheLayout)作为内容和顶部布局之间的包装:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" 
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:paddingLeft="100dip"
android:paddingRight="100dip">
<LinearLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:id="@+id/TheLayout"
    android:layout_gravity="right">
    <TextView android:id="@+id/TextView01" 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent" 
        android:layout_weight="1"
        android:text="this is my text." 
        android:layout_gravity="center_vertical">
    </TextView>
    <ImageView android:id="@+id/ImageView01"
        android:layout_height="wrap_content" 
        android:background="@drawable/icon"
        android:layout_width="fill_parent">
    </ImageView>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)