gpt4 book ai didi

android - ImageView 不在 CardView 的中心

转载 作者:行者123 更新时间:2023-11-29 00:57:11 24 4
gpt4 key购买 nike

我有一张正方形图片,我的 CardView 中的 ImageView 也是正方形的,但它向我展示了这样一张图片: Picture

原图:

Original

这是我的布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@android:color/white"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="true"
android:layout_margin="10dp">

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="374dp"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:id="@+id/illness_image"
android:layout_width="364dp"
android:layout_height="364dp"
android:background="?attr/colorPrimaryDark"
android:cropToPadding="true" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:id="@+id/illness_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textAppearance="?attr/textAppearanceHeadline6"
android:textSize="20sp" />

<TextView
android:id="@+id/illness_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Description"
android:textAppearance="?attr/textAppearanceBody2"
android:textSize="10sp" />

<TextView
android:id="@+id/illness_engagement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Engagment"
android:textAppearance="?attr/textAppearanceBody2"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</android.support.design.card.MaterialCardView>

编辑:对不起,但我不明白。我无法插入我的 XML 代码。

最佳答案

只要在你的 ImageView 中添加 android:layout_gravity="center" 就可以了

试试这个

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
app:cardBackgroundColor="@android:color/white"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="true">

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:id="@+id/illness_image"
android:layout_width="350dp"
android:layout_height="364dp"
android:layout_gravity="center"
android:scaleType="centerInside"
android:src="@drawable/dishu" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:id="@+id/illness_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textAppearance="?attr/textAppearanceHeadline6"
android:textSize="20sp" />

<TextView
android:id="@+id/illness_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Description"
android:textAppearance="?attr/textAppearanceBody2"
android:textSize="10sp" />

<TextView
android:id="@+id/illness_engagement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Engagment"
android:textAppearance="?attr/textAppearanceBody2"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</android.support.design.card.MaterialCardView>

关于android - ImageView 不在 CardView 的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53830512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com