user7660488
user7660488

Reputation:

Image is not setting properly in the ImageView inside a CardView

I am new in android app development. I am developing an app in which I want to set a image of full width but it is taking so much space. I am not understanding, why it is taking so much space? Image URl(full.jpg)

My xml code is below

<?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>

Upvotes: 0

Views: 356

Answers (2)

Qandil Tariq
Qandil Tariq

Reputation: 539

Use android:scaleType="center_inside" property of Imageview.

Upvotes: 0

Cătălin Florescu
Cătălin Florescu

Reputation: 5158

Use android:adjustViewBounds="true" in your ImageView and you could also use android:scaleType="center_inside". More details here.

Upvotes: 1

Related Questions