我有一個textview包裝在一個錶行中。 Textview的內容可能佔用多行,所以我想讓textview可以滾動但沒有成功。如何在TableRow中設置可滾動文本視圖
我已經通過XML和編程的嘗試:
<TableRow
android:id="@+id/tableRow5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/tvTable_Refeeral_Center"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/cell_shaoe"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="@+id/tvTable_Referral_Center_Input"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="@drawable/cell_shaoe"
android:maxLines="2"
android:scrollbars = "vertical"
android:typeface="sans"
android:ems="10"
android:hint="Hours "
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
而在我的班級我設置TextView的運動方法:
referralLabTV.setMovementMethod(ScrollingMovementMethod.getInstance());
我也通過包裝在一個滾動視圖TextView的嘗試,但也不起作用:
<TableRow
android:id="@+id/tableRow6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/tvTable_RefRanges"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Ref Ranges"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/cell_shaoe"
>
<TextView
android:id="@+id/tvrefRanges_Input"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:maxLines="6"
android:typeface="sans"
android:ems="10"
android:hint="Ref Range"
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</ScrollView>
</TableRow>
任何輸入讚賞。
@Shagar
我想你的解決方案,但仍然是相同的,可以olnlt看到,從數據庫添加到TextView的編程文本的第一行。這是整個線性/表格佈局
TableLayout
android:id="@+id/testSelcted_tabl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_selectedTest_Section2"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="5dp"
android:shrinkColumns="1"
>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/tvTable_TAT"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="TAT (hrs)"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="@+id/tvTable_TATText"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="@drawable/cell_shaoe"
android:maxLines="2"
android:scrollbars = "vertical"
android:typeface="sans"
android:ems="10"
android:text="Contact Referral Lab"
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/tvTable_Fixation"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Fixation"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="@+id/tvTFixation_Input"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="@drawable/cell_shaoe"
android:typeface="sans"
android:ems="10"
android:hint="Histology"
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/tvTable_TATUrgent"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Urgent"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="@+id/tvTable_TATUrgetInput"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="@drawable/cell_shaoe"
android:typeface="sans"
android:ems="10"
android:hint="Hours "
android:padding="5dp"
android:textColor="#c4c4c4"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/tvTable_Refeeral_Center"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Referral Lab"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<TextView
android:id="@+id/tvTable_Referral_Center_Input"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="2"
android:background="@drawable/cell_shaoe"
android:maxLines="2"
android:scrollbars = "vertical"
android:typeface="sans"
android:ems="10"
android:hint="Hours "
android:textColor="#c4c4c4"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:id="@+id/tableRow6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3" >
<TextView
android:id="@+id/tvTable_RefRanges"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="@drawable/cell_shaoe"
android:padding="5dp"
android:typeface="sans"
android:text="Ref Ranges"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<!-- wrap a linear layout in a scroll voew which wraps the textview fro textview to scroll -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/cell_shaoe"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tvrefRanges_Input"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="1"
android:typeface="sans"
android:ems="10"
android:hint="Ref Range"
android:textColor="#c4c4c4"
android:padding="5dp"
android:text="jwwhegfrhegihsighhgishgifhwihgawihrgaiwhgihigheihgraiehrgiher"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
</TableRow>
</TableLayout>
是的嘗試,仍然是相同....看看上面的編輯我已經添加了您的代碼...表格佈局也包裹在線性佈局中 – dancingbush