图像在 CardView 内的 ImageView 中设置不正确
Image is not setting properly in the ImageView inside a CardView
我是 android 应用程序开发的新手。我正在开发一个应用程序,我想在其中设置全宽图像,但它占用了太多 space。我不明白,为什么要花这么多space?图片 URl(full.jpg)
我的xml代码如下
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="litifer.awesome.game.cardview.MainActivity"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView1"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="5dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="@android:color/transparent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView1Text"
android:text="Notifications"
android:textSize="20dp"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="40dp"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView1Text1"
android:text="we will let you know about great content when big news happens or when your magazines arrive"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="40dp"
android:textStyle="bold"
android:paddingBottom="30dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView1Text2"
android:text="SETTINGS GOT IT"
android:paddingLeft="160dp"
android:textColor="#f2f"
android:clickable="true"
android:textStyle="bold"
android:paddingBottom="20dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:text="HIGHLIGHTS"
android:textSize="20dp"
android:id="@+id/text"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:text="Recommended based on your interests"
android:paddingLeft="10dp"
android:paddingTop="2dp"
android:textStyle="bold"
/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView2"
android:layout_marginTop="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/image"
android:src="@drawable/full"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout></ScrollView>
在 ImageView
中使用 android:adjustViewBounds="true"
,您也可以使用 android:scaleType="center_inside"
。更多详情 here.
使用 android:scaleType="center_inside"
属性 Imageview。
我是 android 应用程序开发的新手。我正在开发一个应用程序,我想在其中设置全宽图像,但它占用了太多 space。我不明白,为什么要花这么多space?图片 URl(full.jpg)
我的xml代码如下
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="litifer.awesome.game.cardview.MainActivity"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView1"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="5dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="@android:color/transparent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView1Text"
android:text="Notifications"
android:textSize="20dp"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="40dp"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView1Text1"
android:text="we will let you know about great content when big news happens or when your magazines arrive"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="40dp"
android:textStyle="bold"
android:paddingBottom="30dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView1Text2"
android:text="SETTINGS GOT IT"
android:paddingLeft="160dp"
android:textColor="#f2f"
android:clickable="true"
android:textStyle="bold"
android:paddingBottom="20dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:text="HIGHLIGHTS"
android:textSize="20dp"
android:id="@+id/text"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:text="Recommended based on your interests"
android:paddingLeft="10dp"
android:paddingTop="2dp"
android:textStyle="bold"
/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cardView2"
android:layout_marginTop="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/image"
android:src="@drawable/full"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout></ScrollView>
在 ImageView
中使用 android:adjustViewBounds="true"
,您也可以使用 android:scaleType="center_inside"
。更多详情 here.
使用 android:scaleType="center_inside"
属性 Imageview。