在 TableRow 中嵌套 ScrollView
Nesting a ScrollView inside a TableRow
我的意图是通过将 TextView
嵌套在 ScrollView
中使其可滚动(尽管我知道 TextView
可以自行滚动(不需要父 ScrollView
), 我想这样做 :) ) 并让 ScrollView
填满屏幕的整个宽度。
以下代码中的布局有效,但 ScrollView
没有填满屏幕的整个宽度。然而,它的父 TableRow
填满了整个宽度。
我尝试用 fill_parent
、match_parent
和 wrap_content
替换 ScrollView
的 android:layout_width
的值,但其中 none 是完全填满宽度。
<?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>
我找到了解决办法!我将 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>
我的意图是通过将 TextView
嵌套在 ScrollView
中使其可滚动(尽管我知道 TextView
可以自行滚动(不需要父 ScrollView
), 我想这样做 :) ) 并让 ScrollView
填满屏幕的整个宽度。
以下代码中的布局有效,但 ScrollView
没有填满屏幕的整个宽度。然而,它的父 TableRow
填满了整个宽度。
我尝试用 fill_parent
、match_parent
和 wrap_content
替换 ScrollView
的 android:layout_width
的值,但其中 none 是完全填满宽度。
<?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>
我找到了解决办法!我将 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>