【发布时间】:2016-06-04 23:43:38
【问题描述】:
我有几个 CardView,每个左侧都有一个 ImageView。
每个 ImageView 都有一个 layout_weight 以使其适合每个 CardView 的相同宽度和固定高度(在本例中为 80dp)。
当图像水平时,它们看起来不错,例如 1、2 和 5。但是当它们是垂直的时,它们就不适合 3 和 4。
我尝试过:直接在 ImageViews 上声明 layout_weight / 在 LinearLayout 中移动 ImageViews 并在其上声明 layout_weight(实际代码) / Buttons 而不是 ImageViews / 使用 adjustViewBounds 和每个 scaleType。这些都不起作用。
这是我每个 CardView 的实际代码,我将不胜感激!提前谢谢你:)
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="3dp"
android:layout_marginTop="3dp"
android:layout_marginLeft="7dp"
android:layout_marginStart="7dp"
android:layout_marginRight="7dp"
android:layout_marginEnd="7dp">
<LinearLayout android:id="@+id/cardview_inner_linearlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout android:id="@+id/imageview_linearlayout"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_weight="7">
<ImageView android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/halloween1" />
</LinearLayout>
<LinearLayout android:id="@+id/whitearea_linearlayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
// White area to the right of the image
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
【问题讨论】:
标签: android android-layout imageview android-linearlayout android-cardview