Question

Basically, my listView item is getting cutoff if the user were to input a lot of text into it. I've searched for a solution, but could not find one so hopefully this helps others too.

I have set textView and ListView to wrap_content I have set textView to android:singleLine="false"

This is how the textView being cutoff looks

My xml for the individual listitem:

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


<TextView
android:id="@+id/tvItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/bDelete"
android:layout_alignBottom="@+id/bDelete"
android:layout_toLeftOf="@+id/bDelete"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
android:id="@+id/bDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="15dp"
android:layout_alignParentTop="true"
android:layout_marginRight="5dp"
android:text="DONE" />

</RelativeLayout>

My xml for the whole main screen layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:background="@drawable/artport">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

<Button
android:layout_alignParentRight="true"
android:id="@+id/bAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add" />

<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/bAdd"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/bAdd"
android:contentDescription="@string/addItemContentDescription"
android:ems="10"
android:hint="@string/addItemHint" />

</RelativeLayout>   


<LinearLayout 
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ListView
android:id="@+id/myListView"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" 
/>

<Button
android:id="@+id/bClearedList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ad"
android:layout_weight="0"
android:text="View Deleted Items" />

<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:adUnitId="ca-app-pub-XXXXXXXXXXXXXXXXXXX"
ads:loadAdOnCreate="true"
android:layout_alignParentBottom="true"
>
</com.google.ads.AdView>
</LinearLayout>


</LinearLayout>
Was it helpful?

Solution 2

Try out below code for your listitems:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    android:gravity="center" >

    <TextView
        android:id="@+id/tvItem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:gravity="center_vertical"
        android:layout_toLeftOf="@+id/bDelete"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/bDelete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="5dp"
        android:layout_alignBaseline="@+id/tvItem"
        android:text="DONE"
        android:gravity="center_vertical"
        android:textSize="15dp" />

</RelativeLayout>

OTHER TIPS

Remove

android:layout_alignBottom="@+id/bDelete"

in your TextView

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top