我有一个父LinearLayout
,我有2 CardViews
。我在ImageView
内有一个CardView
。当我在任何ImageView
中加载图片时,它没有占据CardView
的完整宽度。 ImageView
和CardView
之间存在轻微的白色差距。如何将ImageView
完全重叠在CardView
上?这是我的布局。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#F5F5F5"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="@+id/adhaarCardFrontUpload"
android:layout_width="0dp"
android:layout_height="@dimen/adhaar_height"
android:layout_marginBottom="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
app:cardCornerRadius="5dp"
app:cardPreventCornerOverlap="false"
app:cardElevation="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/ic_add" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:padding="2dp"
android:text="@string/upload_adhaar_front"
android:textColor="@color/colorAccent" />
</LinearLayout>
<ImageView
android:id="@+id/adhaarCardFrontImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:visibility="visible" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/adhaarCardBackUpload"
android:layout_width="0dp"
android:layout_height="@dimen/adhaar_height"
android:layout_marginBottom="5dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
app:cardPreventCornerOverlap="false"
app:cardCornerRadius="5dp"
app:cardElevation="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/ic_add" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:padding="2dp"
android:text="@string/upload_adhaar_back"
android:textColor="@color/colorAccent" />
</LinearLayout>
<ImageView
android:id="@+id/adhaarCardBackImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:visibility="visible" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:1)
将adjustViewBounds更改为false。
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:scaleType="fitXY"
android:src="@drawable/ic_add" />
如果您希望ImageView调整其边界以保持其drawable的纵横比,则将其设置为true。
答案 1 :(得分:0)
您应该使用MATCH_PARENT
。
视图请求的高度或宽度的特殊值。 MATCH_PARENT意味着视图要与其父视图一样大, 减去父级的填充(如果有的话)。
试试这种方式,
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/ic_add"
/>
尝试
android:adjustViewBounds="true"
android:scaleType="fitCenter"