Reputation: 391
I have a ListView
with my own XML. It contains a TextView
. There can be 1 up to 6 lines of text.
The problem is that it shows only 2 lines of text. How can I change the size of an item in a ListView
dynamically to show the whole text?
My xml, where txt2
contains 1-6 line of text:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="Test"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="#000000"
/>
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
android:textColor="#000000"
/>
</LinearLayout>
</LinearLayout>
Upvotes: 0
Views: 180
Reputation: 767
You can also Just give a fixed
layout_width for TextView.
And the whole 1-6 lines of text will wrap to according to height...
Upvotes: 0
Reputation: 767
Make your list view to be horizontally scrollable
i.e.
Add your
<ListView> inside <HorizontalScrollView>
Now you can horizontally scroll to see full text...
Upvotes: 0
Reputation: 2535
Use this to calculate dynamically change
String abc ="text which you will use";
TextView textView = null; // assign here
textView.setMaxLines(abc.length()/ 40);
textView.setMinLines(abc.length()/ 40);
Upvotes: 0
Reputation: 1548
Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="Test"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:textColor="#000000"
/>
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
android:textColor="#000000"
/>
</LinearLayout>
Upvotes: 1