Imageview layout_weight in LinearLayout not working well

647 Views Asked by At

I am working on displaying view with both portrait and landscape.

In portrait, I have code that works properly.

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

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

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        />
    <LinearLayout
        android:id="@+id/text_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:orientation="vertical"
        >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />

    </LinearLayout>
  </LinearLayout></ScrollView>

The image displays perfectly with above code.

However, in landscape. I have:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>

<ImageView
    android:id="@+id/image"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:layout_margin="10dp"
    android:adjustViewBounds="true"
    android:scaleType="centerCrop"
    />

<ScrollView 
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1">
        <LinearLayout
            android:id="@+id/text_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:orientation="vertical"
            android:visibility="gone">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
             />

        </LinearLayout>
</ScrollView>
</LinearLayout>

The image couldn't display perfectly. It only displays very small part of the image. I tried all scaleType attributes, but none of them works.

Do you guys have any idea? Thanks.

1

There are 1 best solutions below

0
On

You are using android:scaleType="centerCrop"

-So you Image will be croped from center and it will show as it is .. -But you want it to be full width and height so ...

My suggestion would be using of android:scaleType="FITXY"