我有这样的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:minWidth="100dp" >
<TextView
android:id="@+id/txt_what_way"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="4"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="3">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="3">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
</LinearLayout>
我希望它看起来像:
- TextView-宽度的40%,带ImageView的布局-宽度的30%,带ImageView的布局-宽的30%
然而,输出是:
TextViewImageViewImageView----------------free space----------------------------------
在您的情况下使用android:weightSum="10"使用android:background代替android:src,用这个替换你的xml文件
<TextView
android:id="@+id/txt_what_way"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="4"
android:text="test"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_weight="3"
android:background="@drawable/s1"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_weight="3"
android:background="@drawable/s1"/>
</LinearLayout>
您可能会得到失真的图像
这应该做到,尽管它会扭曲您的图像。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minWidth="100dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/txt_what_way"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:scaleType="fitCenter"
android:src="@drawable/icon" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:scaleType="fitCenter"
android:src="@drawable/icon" />
</LinearLayout>