我目前正在尝试学习Android。现在一直在阅读教程和手册。 我被困在布局问题。椭圆大小不工作在这张表布局
我从网页中删除内容并将其显示给用户。这是我的应用程序的工作。
我的布局如下:
<?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>
通过代码,我会通过TableRows循环,并添加每两个TextViews。下面是一个示例一块吧:
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);
}
的问题是,setEllipsize()对每个的TableRow第一的TextView没有做任何事情。它只显示第一个TextView的文本(长文本溢出宽度),TextView2甚至不显示。
当我尝试setEllipsize()和setSingleLine()在一个现有的TextView(我的布局中的第一个TextView - 你可以从上面的XML,这是在表格布局上面)看到,它工作正常。
任何想法,我哪里出错了?或者有什么建议?
感谢提前:)
谢谢:)我试图使用'设定的TextView的最大线setMaxLines(1)'。但这不起作用。我会尝试将'Layout_Height'设置为'fill_parent'。为此我必须创建一个TableLayout参数并将规则添加到它? – 2012-04-06 02:37:42
也玩宽度。在包装内容中,在宽度根据内容而变化的情况下,可以看到这个问题。 – Shubhayu 2012-04-06 04:33:44
我曾尝试将fill_parent设置为所有TextViews的父项。但那没有奏效。现在试图玩宽度。要为驻留在TableRow(位于TableLayout中)的TextView设置布局参数(FILL_PARENT),是否必须创建TableLayout的对象并将其传递给TextView的setLayoutParams? – 2012-04-08 06:13:52