I am currently trying to learn Android. Have been reading tutorials and manual for some days now. I am stuck at a layout issue.
I'm scrapping the content from a webpage and displaying it to the user. That's the working of my app.
My layout is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:padding="5px">
<TextView
android:id="@+id/tvOutput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0" android:id="@+id/tblOutput">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow8"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow10"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow11"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
<Button
android:id="@+id/btnBack"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/lblBack" android:layout_marginTop="10dip"/>
<Button
android:id="@+id/btnSendSMS"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="@string/lblSendSMS" />
</LinearLayout>
</ScrollView>
Via code, I'll loop through the TableRows and add two TextViews each. Below is a sample piece of it:
for(i=1;i<=11;i++){
TextView tv1 = new TextView(getApplicationContext());
TextView tv2 = new TextView(getApplicationContext());
//get values and store it in strValue1 & strValue2
//....
tv1.setText(strValue1); //a long text
tv2.setText(strValue2); //would always be a 3 letter value
//tv1.setEllipsize(TruncateAt.MARQUEE);
//tv1.setMarqueeRepeatLimit(1);
tv1.setSingleLine(true);
tv1.setEllipsize(TruncateAt.END);
tv1.setGravity(Gravity.LEFT);
tr = (TableRow) findViewById( getResources().getIdentifier("tableRow"+i, "id", getPackageName()));
tr.addView(tv1);
tr.addView(tv2);
}
The problem is, setEllipsize() for the first TextView on each TableRow is not doing anything. It just shows the text of first TextView (long text overflowing the width) and the TextView2 is not even displayed.
When I tried the setEllipsize() and setSingleLine() on an existing TextView (the very first TextView in my layout - you could see from the above XML, which is above the Table Layout), it's working fine.
Any ideas where I went wrong ? Or any suggestions ?
Thanks in advance :)
You need to set a fixed height for the TextView with any one of the ways possible. Setting the number of lines or just setting the height of the TextView layout. If you dont then since ure textview has wrap_content as height, it will resize and show all the text.
So first fix the size of the textview and then setellipsize()
setMaxLines(1)
. But that's not working. I will try setting theLayout_Height
tofill_parent
. For this I have to create a TableLayout Params and add the rules to it - Akhilesh B Chandran 2012-04-06 02:37