我的意图是通过将TextView
嵌套在ScrollView
内来使TextView
可滚动(虽然我知道ScrollView
可以自己滚动(不需要父ScrollView
}}),我想以这种方式做:))并让ScrollView
填充整个屏幕宽度。
以下代码中的布局有效,但TableRow
未填充整个屏幕宽度。但是,其父android:layout_width
填充整个宽度。
我尝试用ScrollView
,fill_parent
和match_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()
答案 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>