Android ImageView不是';t中心内卡德维尤
我有一个方形图像,我的CardView中的ImageView也是方形的,但它向我显示了如下图片: 原图: 这是我的布局文件:Android ImageView不是';t中心内卡德维尤,android,xml,android-layout,Android,Xml,Android Layout,我有一个方形图像,我的CardView中的ImageView也是方形的,但它向我显示了如下图片: 原图: 这是我的布局文件: <?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.an
<?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代码。只需在图像视图中添加
android:layout\u 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>
<?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="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/illness_image"
android:layout_width="match_parent"
android:layout_height="364dp"
android:background="?attr/colorPrimaryDark"
android:scaleType="fitXY"
/>
<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>
试试这个
<?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>
<?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="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/illness_image"
android:layout_width="match_parent"
android:layout_height="364dp"
android:background="?attr/colorPrimaryDark"
android:scaleType="fitXY"
/>
<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:scaleType="centerInside"
到您的ImageView
<ImageView
android:id="@+id/illness_image"
android:layout_width="364dp"
android:scaleType="centerInside"
android:layout_height="364dp"
android:background="?attr/colorPrimaryDark"
android:cropToPadding="true" />
您可以按如下方式使用:-
<ImageView
android:id="@+id/illness_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:background="?attr/colorPrimaryDark"
/>
显示xml文件..发布您的卡片视图和布局file@OliverWeidner,在xml
上显示您的ImageView
属性,或者在此问题中添加ImageView
的代码。很抱歉,我插入它时遇到问题。现在它就在那里。删除这个标签,在图像视图上使用。它不工作,它显示了相同的割礼图片,但是谢谢。@OliverWidner将线性布局的宽度更改为android:layout\u width=“match\u parent”
它看起来更好,但整体情况还不清楚。好了,我们走吧,它就在那里!非常感谢!谢谢你,祝你也一样!:)删除android:Croptoppadding,然后重试