我有一个包含在表格行中的textview。 Textview的内容可能会占用多行,所以我想让textview可滚动但没有成功。
我尝试过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包装在scrollview中,但也不起作用:
<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
我尝试了你的解决方案,但仍然是相同的,可以看到以编程方式从数据库添加到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>
答案 0 :(得分:0)
只需将一个LinearLayout放在ScrollView中。 并使TextView高度宽度与其父级匹配。 这是修改后的代码。
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@android:color/holo_blue_light"
>
<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="6"
android:typeface="sans"
android:ems="10"
android:hint="Ref Range"
android:textColor="#c4c4c4"
android:padding="5dp"
android:text="Hello\nHello\nHello\nHello\nHello\nHello\nHello\n"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
答案 1 :(得分:0)
我能做到这一点的唯一方法是将textview更改为带有属性的editview:
机器人:编辑=&#34;假&#34; 机器人:cursorVisible =&#34;假&#34;