如何在具有权重的 LinearLayout 中根据比例缩放图像,然后在图像右侧放置标签?下面的示例显示了 3 行等高,每行都需要将 TextView 定位在它们的右侧。简而言之:左边是图像,右边是文本。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ImageView
android:id="@+id/a1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#33B5E5"
android:contentDescription="@string/app_name"
android:scaleType="fitStart"
android:src="@android:drawable/star_big_on" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/a1"
android:text="@string/app_name" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ImageView
android:id="@+id/a2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#AA66CC"
android:contentDescription="@string/app_name"
android:scaleType="fitXY"
android:src="@android:drawable/star_big_on" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/a2"
android:text="@string/app_name" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ImageView
android:id="@+id/a3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FF4444"
android:contentDescription="@string/app_name"
android:scaleType="fitStart"
android:src="@android:drawable/star_big_on" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/a3"
android:text="@string/app_name" />
</RelativeLayout>
</LinearLayout>