【问题标题】:Nesting a ScrollView inside a TableRow将 ScrollView 嵌套在 TableRow 中
【发布时间】:2016-06-04 15:40:40
【问题描述】:

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

以下代码中的布局有效,但ScrollView 没有填满屏幕的整个宽度。但是,它的父 TableRow 填充了整个宽度。

我尝试将ScrollViewandroid:layout_width 的值替换为fill_parentmatch_parentwrap_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 android-layout android-scrollview android-tablelayout


    【解决方案1】:

    我找到了解决办法!我将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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      • 2014-04-07
      • 2014-09-24
      • 2015-06-27
      相关资源
      最近更新 更多