Search code examples
androidlistviewlistviewitem

Listview can't displayed the last item


This is the my current listivew: enter image description here

My problem is i can't display my last item in the list. It's like getting cut by my phone.

Here is the xml code:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">
    <RelativeLayout
        android:orientation="vertical"
        android:id="@+id/border"
        android:layout_width="match_parent"
        android:layout_height="280dp"

        android:background="@drawable/dfcomment3"
        android:layout_weight="0.07">


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

            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:text="Add comment"
                android:id="@+id/button12"
                android:layout_marginTop="215dp"
                android:layout_marginLeft="5dp" />
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:text="Update Post"
                android:id="@+id/button13"
                android:layout_marginTop="215dp" />
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:text="Close This"
                android:id="@+id/button14"
                android:layout_marginTop="215dp" />


        </LinearLayout>

        <TextView
            android:layout_marginLeft="10dp"
            android:textSize="35dp"
            android:id="@+id/textView11"
            android:gravity="center"
            android:text="ID"
            android:textStyle="bold"
            android:textColor="#994495"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView12"
            android:text="Name"
            android:textSize="16dp"
            android:textColor="#994495"
            android:layout_marginTop="190dp"
            android:layout_marginLeft="210dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/textView13"
            android:text="Lastname"
            android:textStyle="bold"
            android:textSize="16dp"
            android:layout_marginLeft="90dp"
            android:textColor="#994495"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/id"
            android:layout_toEndOf="@+id/id"
            android:layout_marginTop="5dp" />

        <TextView
            android:id="@+id/textView14"
            android:text="title"
            android:textSize="15dp"
            android:textColor="#994495"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="260dp"
            android:layout_below="@+id/name"
            android:layout_alignStart="@+id/name"
            android:layout_marginTop="190dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="descr"
            android:textSize="21dp"
            android:textColor="#994495"
            android:id="@+id/textView15"
            android:layout_marginLeft="110dp"
            android:layout_marginTop="60dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="dept"
            android:textStyle="italic"
            android:textColor="#994495"
            android:id="@+id/textView16"
            android:layout_marginLeft="180dp"
            android:layout_marginTop="30dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="tags"
            android:textStyle="italic"
            android:textSize="14dp"
            android:textColor="#994495"
            android:id="@+id/textView17"
            android:layout_marginLeft="120dp"
            android:layout_marginTop="30dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="status"
            android:textSize="25dp"
            android:textStyle="bold"
            android:textColor="#70CC86"
            android:id="@+id/textView18"
            android:layout_marginLeft="290dp"
            android:layout_marginTop="10dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="date"
            android:textColor="#994495"
            android:id="@+id/textView19"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="190dp" />
    </RelativeLayout>

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

        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>
</LinearLayout>

As much as possible i want to stick with the listview because i'm not familiar with the recyclerview. if theres any way to fix this, i would be glad. Check the image for the reference of my problem.

There's actually 4 items in the list and i can only view 2 items.


Solution

  • Change you xml to :

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1">
        <RelativeLayout
            android:orientation="vertical"
            android:id="@+id/border"
            android:layout_width="match_parent"
            android:layout_height="280dp"
            android:layout_weight="0.07"--> Delete this
            >
          ....
        </RelativeLayout>
    
        <LinearLayout 
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:layout_weight="1" -> Add this
            android:layout_height="0dp" >
    
            <ListView
                android:id="@+id/listView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
    
        </LinearLayout>
    </LinearLayout>