В настоящее время я пытаюсь изучить 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() для первого TextView на каждом TableRow не делает ничего. Он просто показывает текст первого TextView (длинный текст, переполненный шириной), и TextView2 даже не отображается.
Когда я попытался установить setEllipsize() и setSingleLine() в существующий TextView (самый первый TextView в моем макете - вы можете видеть из вышеприведенного XML, который находится выше макета таблицы), он работает нормально.
Любые идеи, в которых я поступил не так? Или любые предложения?
Заранее спасибо :)
Спасибо :) Я попытался установить максимальные строк TextView с помощью 'setMaxLines (1)'. Но это не работает. Я попробую установить 'Layout_Height'' fill_parent'. Для этого мне нужно создать Parallels TableLayout и добавить к нему правила? –
Играйте с шириной тоже. SOmetimes в содержимом обертки, где ширина изменяется в зависимости от содержимого, эта проблема видна. – Shubhayu
Я попытался установить fill_parent всем родителям TextViews. Но это не сработало. Теперь попробуйте сыграть с Width. Чтобы установить параметры макета (FILL_PARENT) для TextView, находящегося в TableRow (внутри TableLayout), мне нужно создать объект TableLayout и передать его в setLayoutParams из TextView? –