Search code examples
androidandroid-xmlandroid-scrollview

Image in scrollview doesn't display properly


I having a problem to display the image nicely at different devices. Example of S3 Device, they displayed the way I wanted: S3

However is S6 Device, the image display is too small especially for portrait images. S6

Anyone got idea how to solve this issues because I tried to use weight , match parent etc doesn't really work on it. p.s. when i put my imageview above scrollview , sometime work quite perfectly.

Below is my current XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <include
        layout="@layout/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/ivEventInfoPoster"
                    android:src="@drawable/carfreeday"
                    android:scaleType="center"
                    android:contentDescription="@string/common_img_desc"
                    />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/tvEventInfoTitle"
                    android:paddingTop="5dp"
                    android:text="Title"
                    android:textSize="24sp"
                    android:textStyle="bold"
                    />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/tvEventInfoDesc"
                    android:text="Desc"
                    android:layout_marginTop="3dp"
                    android:textSize="16sp"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/tvEventInfoDate"
                    android:text="Date"
                    android:textSize="16sp"
                    android:layout_marginBottom="10dp"/>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

Solution

  • Try this with your ImageView

    <ImageView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:id="@+id/ivEventInfoPoster"
      android:src="@drawable/carfreeday"
      android:scaleType="fitStart"
      android:adjustViewBounds="true"                 
      android:contentDescription="@string/common_img_desc"
    />