Home » Android » android – ListView items gone off screen-Exceptionshub

android – ListView items gone off screen-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

ListView in XML
The row cut off when the program runs
My ListView Adapter
The row layout

The problem is when I run the program the view cuts like what shown in the picture above
I don’t know what the exact sort of problem, so if you need anything to show just ask
I am using kotlin by the way

EDIT 1:
result_row.xml this is the XML for the row that shows in the ListView

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/itemName"
            android:layout_width="200dp"
            android:layout_height="40dp"
            android:gravity="center"
            android:text="Name"
            android:textColor="#000000"
            android:textSize="16sp" />


        <View
            android:id="@+id/lineView2"
            android:layout_width="2dp"
            android:layout_height="40dp"
            android:background="#010101" />

        <TextView
            android:id="@+id/itemWeight"
            android:layout_width="100dp"
            android:layout_height="40dp"
            android:gravity="center"
            android:text="Item Weight"
            android:textColor="#000000"
            android:textSize="16sp" />

        <View
            android:id="@+id/lineView1"
            android:layout_width="2dp"
            android:layout_height="40dp"
            android:background="#010101" />

        <TextView
            android:id="@+id/itemPrice"
            android:layout_width="100dp"
            android:layout_height="40dp"
            android:gravity="center"
            android:text="Price"
            android:textColor="#000000"
            android:textSize="16sp" />


    </LinearLayout>


</FrameLayout>
How to&Answers:

Your TextViews have fixed widths that total greater than the width of the screen:

android:layout_width="200dp"
...
android:layout_width="100dp"
...
android:layout_width="100dp"

Android phones can be as narrow as 320dp, so it’ll get cut off. You need to modify your layout to use the available space, not hardcode fixed widths. Or, if you really want to use fixed widths, they need to be smaller (shouldn’t add up to more than 320dp).

Answer:

in your layout xml file edit

layout_width="0dp"
layoyt_height="0dp"