我的意图是TextView
通过将其嵌套在a中来使其可滚动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>
我找到了解决方案!我加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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句