我想要一个回收站 View 行作为给定的数字。基本上, ImageView 将具有固定尺寸。两个 TextView 应覆盖整个空间,但不应将 ImageView 移出屏幕。它也不应该裁剪它。 请忽略填充和边距。除了 ImageView 和两个 TextView 之间会有边距。
我试过的:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.8">
<TextView
android:id="@+id/tv1"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_alignParentStart="true"
android:layout_below="@id/tv1"
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"/>
</RelativeLayout>
<ImageView
android:id="@+id/img"
android:layout_weight="0.2"
android:layout_width="85dp"
android:layout_height="50dp"
android:layout_marginStart="12dp"
android:layout_centerVertical="true"
android:scaleType="centerCrop"/>
</LinearLayout>
问题在于 ImageView 的尺寸会随着 TextView 中的文本而变化。我不要那个。我想要固定尺寸。
我本可以将整个内容保持在相对布局中,但我无法在两个 TextView 和 ImageView 之间保持边距。
最佳答案
你的 RelativeLayout 应该是:
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
从 ImageView
中删除 android:layout_weight
这将拉伸(stretch) RelativeLayout 以适应空间并保持 ImageView
相同的大小。
关于java - 如何设置这个 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45312921/