0

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?

2
  • Change the height of parent layout from 100dp to lower then this and try Commented May 2, 2016 at 12:45
  • Set the height of the root layout of the item as wrap_content. Commented May 2, 2016 at 12:52

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.