我最后通过权重属性解决了我的帖子问题,但是当我给出多行文本时,一个问题就出现了Textview没有显示在这个网址中http://imgur.com/ApL5c
如何在代码中添加滚动视图?
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:weightSum="11"
android:layout_margin="5dp">
<TableRow>
<TextView
style="@style/StyleLabel"
android:text="@string/name_lbl"/>
<TextView
android:id="@+id/nameText"
android:layout_weight="2"
style="@style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="@style/StyleLabel"
android:text="@string/cap_lbl"/>
<TextView
android:id="@+id/capText"
android:layout_weight="2"
style="@style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="@style/StyleLabel"
android:text="@string/code_lbl"/>
<TextView
android:id="@+id/codeText"
android:layout_weight="1"
style="@style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="@style/StyleLabel"
android:text="@string/DoneDate_lbl"/>
<TextView
android:id="@+id/Location_lbl"
android:layout_weight="1"
style="@style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="@style/StyleLabel"
android:text="@string/Notes_lbl"/>
<TextView
android:id="@+id/Notes_lbl"
android:layout_weight="4"
style="@style/StyleText"
/>
</TableRow>
<TableRow>
<TextView
style="@style/StyleLabel"
android:text="@string/person_lbl"/>
<TextView
android:id="@+id/Person_lbl"
android:layout_weight="1"
style="@style/StyleText"/>
</TableRow>
答案 0 :(得分:0)
只需将其环绕在滚动视图中,如下所示 -
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:weightSum="11"
android:layout_margin="5dp">
<TableRow>
<TextView
android:text="textview1"/>
<TextView
android:id="@+id/nameText"
android:text="tewgoijirtgujerioug"
android:lines="15" //You can add lines to make your textview occupy the no of lines you want instead of weight.
android:layout_weight="2"
/>
</TableRow>
............
.............
</TableLayout>
</ScrollView>
希望这有帮助。