将ScrollView嵌套在TableRow

时间:2016-06-04 15:40:41

标签: android android-layout android-scrollview android-tablelayout

我的意图是通过将TextView嵌套在ScrollView内来使TextView可滚动(虽然我知道ScrollView可以自己滚动(不需要父ScrollView }}),我想以这种方式做:))并让ScrollView填充整个屏幕宽度。

以下代码中的布局有效,但TableRow未填充整个屏幕宽度。但是,其父android:layout_width填充整个宽度。

我尝试用ScrollViewfill_parentmatch_parent替换wrap_content <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/activity_my"> <TableRow> <EditText android:id="@+id/edit_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/edit_message" android:layout_weight="1"/> <Button android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/button_send" android:onClick="sendMessage"/> </TableRow> <TableRow> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="vertical" android:fillViewport="true"> <TextView android:id="@+id/message_box" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </ScrollView> </TableRow> </TableLayout> 的值,但它们都没有完全填充宽度。< / p>

fseek()

1 个答案:

答案 0 :(得分:2)

我找到了解决方案!我将android:layout_weight="1"添加到ScrollView

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:layout_weight="1"
        android:fillViewport="true">
        <TextView
            android:id="@+id/message_box"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
</ScrollView>