I am using Table layout. I have two(columns) text-views in table row. I want to apply android:ellipsize="end"
at the end of the textView
.
But it is not working for me, see the screen shot below. Please give me any idea, how to apply ellipsize to the textview
inside a table row
.
Here is the code :
<TableLayout
android:id="@+id/linerLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dip"
android:background="@drawable/shape1"
android:stretchColumns="2" >
<TableRow
android:id="@+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Product used for "
android:textColor="@color/black_color" />
<TextView
android:id="@+id/productusedfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="@color/black_color" />
</TableRow>
<TableRow
android:id="@+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Treatment for "
android:textColor="@color/black_color" />
<TextView
android:id="@+id/treatementfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="@color/black_color" />
</TableRow>
<TableRow
android:id="@+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Horse Name "
android:textColor="@color/black_color" />
<TextView
android:id="@+id/horsename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="@color/black_color" />
</TableRow>
<TableRow
android:id="@+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Where "
android:textColor="@color/black_color" />
<TextView
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="@color/black_color" />
</TableRow>
Try this
You have to use following property. Because textview width is wrap_content
so it is going outside from the tablerow. So if you use this property then it will work: android:layout_weight="1"
.
<TableLayout
android:id="@+id/linerLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="10dip"
android:background="@drawable/shape1"
android:stretchColumns="2" >
<TableRow
android:id="@+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Product used for "
android:textColor="@color/black_color" />
<TextView
android:id="@+id/productusedfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:layout_weight="1"
android:padding="5dp"
android:singleLine="true"
android:text="fjdsngfksngfkfngkaklmngkldfmnkldgfnskldngkldnsklnghdnklgfnkdtgfndkgfn"
android:textColor="@color/black_color" />
</TableRow>
<TableRow
android:id="@+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Treatment for "
android:textColor="@color/black_color" />
<TextView
android:id="@+id/treatementfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:layout_weight="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="@color/black_color" />
</TableRow>
<TableRow
android:id="@+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Horse Name "
android:textColor="@color/black_color" />
<TextView
android:id="@+id/horsename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:ellipsize="end"
android:minLines="1"
android:layout_weight="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="@color/black_color" />
</TableRow>
<TableRow
android:id="@+id/TableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Where "
android:textColor="@color/black_color" />
<TextView
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:layout_weight="1"
android:padding="5dp"
android:singleLine="true"
android:text="TextView"
android:textColor="@color/black_color" />
</TableRow>
</TableLayout>
It may work for you.
//try this
android:maxEms="9"
this attributes will do change you maxEms according to your length what you want to achive.
<TextView
android:id="@+id/productusedfor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:minLines="1"
android:padding="5dp"
android:maxEms="5"
android:singleLine="true"
android:text="TextView"
android:textColor="@color/black_color" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With