Milla
Milla

Reputation: 503

Android ListView Item Layout getting screwed up

I tried to customize the layout of my ListView so I made up the following layout file:

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        tools:context=".workout.WorkoutPlanFragment"
        android:paddingRight="10dp"
        android:orientation="horizontal">

<LinearLayout
        android:id="@+id/edit_view"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_column="0"
        android:layout_row="0"
        android:visibility="gone">
    <ImageView
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_delete"
            android:layout_column="0"
            android:layout_row="0"
            android:layout_rowSpan="3"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:layout_marginRight="15dp"
            android:layout_marginLeft="15dp"
            android:id="@+id/image_view_delete_workout_plan"/>
    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/image_view_move_down"
            android:src="@drawable/ic_down" android:layout_gravity="center_vertical"
            android:layout_marginRight="15dp"/>
    <ImageView android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:id="@+id/image_view_move_up"
               android:src="@drawable/ic_up" android:layout_gravity="center_vertical"
               android:layout_marginRight="15dp"/>
</LinearLayout>
<GridLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/workout_plan_fragment" android:layout_column="1" android:layout_row="0">
    <ImageView
            android:layout_width="93dp"
            android:layout_height="match_parent"
            android:src="@drawable/img_workout"
            android:id="@+id/imageView5"
            android:layout_column="0" android:layout_row="0" android:layout_rowSpan="3"
            android:paddingBottom="4dp" android:paddingTop="4dp" android:layout_marginRight="10dp"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Someting"
            android:alpha="1"
            android:id="@+id/text_view_plan_name" android:layout_gravity="center_vertical"
            android:layout_column="1" android:layout_row="0"
            android:textColor="#5a70ff"
            android:textSize="26dp" android:layout_marginTop="5dp"/>
    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:text="asdf"
            android:id="@+id/text_view_anz_exercises" android:layout_row="1" android:layout_column="1"
            android:layout_rowWeight="0.1" android:alpha="1" android:textSize="15dp"/>
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceSmall" android:text="blablablablablabla"
              android:id="@+id/text_view_last_workout" android:layout_row="2" android:layout_column="1"
              android:layout_marginBottom="5dp"/>
</GridLayout>

When I use this layout on a Fragment or just check it in the design tab it looks totally fine like this: Layout_good

But as soon as I apply this layout to a ListView item it turns out looking like that: Layout_bad

I already tried replacing the GridLayout by a LinearLayout or something like that but it always looks like that...

How can I make the ListView item look like the designed Layout?

Upvotes: 0

Views: 54

Answers (1)

Jay Rathod
Jay Rathod

Reputation: 11245

Try this code.

<GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingRight="10dp" />

    <LinearLayout
        android:id="@+id/edit_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_column="0"
        android:layout_row="0"
        android:orientation="horizontal"
        android:visibility="gone">

        <ImageView
            android:id="@+id/image_view_delete_workout_plan"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_row="0"
            android:layout_rowSpan="3"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/image_view_move_down"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="15dp"
            android:src="@drawable/ic_launcher" />

        <ImageView
            android:id="@+id/image_view_move_up"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="15dp"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <GridLayout
        android:id="@+id/workout_plan_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_row="0">

        <ImageView
            android:id="@+id/imageView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_marginRight="10dp"
            android:layout_row="0"
            android:layout_rowSpan="3"
            android:paddingBottom="4dp"
            android:paddingTop="4dp"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/text_view_plan_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="5dp"
            android:layout_row="0"
            android:alpha="1"
            android:text="Someting"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#5a70ff"
            android:textSize="26dp" />

        <TextView
            android:id="@+id/text_view_anz_exercises"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_row="1"
            android:layout_rowWeight="0.1"
            android:alpha="1"
            android:text="asdf"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textSize="15dp" />

        <TextView
            android:id="@+id/text_view_last_workout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_marginBottom="5dp"
            android:layout_row="2"
            android:text="blablablablablabla"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </GridLayout>

Upvotes: 1

Related Questions