Reputation: 8408
I'm trying to get my text of my text view within the table row to appear on more than one line, but for some reason it doesn't wrap properly and I end up with this (see screenshot). I know the text view has something to do this it but I don't know what I causing this problem to occur. What can be done to resolve this issue?
Screenshot
List item XML
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow>
<ImageView
android:id="@+id/img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
Upvotes: 9
Views: 8342
Reputation: 15821
You need specify android:layout_weight="1"
.
This value is telling to
TableRow
that theTextView
is need to be equivalent tomatch_parent
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
>
<ImageView
android:id="@+id/img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"/>
<TextView
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:layout_weight="1"
android:text="This is a long long long long text fodshfkjsdkjfjsh js hdfjksh kjdhf kjshdkjf"
android:textAppearance="?android:attr/textAppearanceLarge"/>
</TableRow>
</TableLayout>
Upvotes: 38
Reputation: 83
Try below code may help
<com.project_name.JustifiedTextView.JustifiedTextView
android:id="@+id/txtHide"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="25dp"
xmlns:noghteh="http://noghteh.ir"
android:text=""
android:textColor="@color/BlueText"
android:textSize="@dimen/text_size" />
Link: https://github.com/navabi/JustifiedTextView
Upvotes: 0
Reputation: 6515
give <TableRow>
attributes
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/img"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:singleLine="false"
android:paddingRight="10dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
Upvotes: 0
Reputation: 916
Simple fix would be to increase margin end, try :
<TextView
android:id="@+id/txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"
android:layout_marginEnd="30dp"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceLarge" />
Upvotes: -1