Devrath
Devrath

Reputation: 42824

Styling Custom adapter for gridview

What I am trying to get ::
< I am trying to display same look on both landscape and portrait mode>

enter image description here


What i am currently having :: < Observe the imageview looks differently in different orientation modes > height of the imageview is more in portrait mode

enter image description hereenter image description here


grid_single.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:background="#222222"
    android:orientation="vertical"
    android:padding="10dp" >

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

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#E6E6E6"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/grid_image"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:src="@drawable/eleven" >
                </ImageView>
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#FFFFFF"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/grid_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:text="Text"
                    android:textSize="12sp" >
                </TextView>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

activity_main.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"
    tools:context=".MainActivity" >

    <GridView
        android:id="@+id/grid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null"
        android:listSelector="#00000000"
        android:numColumns="auto_fit" />

</LinearLayout>

Upvotes: 1

Views: 1356

Answers (2)

Ovi
Ovi

Reputation: 60

Use this XML instead..

grid_single.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="wrap_content"
    android:background="#222222"
    android:orientation="vertical"
    android:padding="10dp" >

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

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#FFFFFF"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#E6E6E6"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/grid_image"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:src="@drawable/eleven" >
                </ImageView>
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#FFFFFF"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/grid_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="10dp"
                    android:text="Text"
                    android:textSize="12sp" >
                </TextView>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

Upvotes: 0

SuppressWarnings
SuppressWarnings

Reputation: 4182

Try changing your ImageView xml to this:

<ImageView
    android:id="@+id/grid_image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:scaleType="fitXY"
    android:src="@drawable/eleven" >
</ImageView>

You have a good sample of different android:scaleType displays, and how they behave here.

Upvotes: 2

Related Questions