首页 > 解决方案 > 如何修复嵌套在 ScrollView 中的 BoxInsetLayout 内的包装元素

问题描述

我想实现可滚动的 BoxInsetlayout,子元素从顶部和侧面装箱。在 ScrollView 嵌套的 BoxInsetLayout 的子项中包装组件似乎有问题。这是因为不能为 wrap-content 设置 BoxInsentLayout 吗?

这是我的例子:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/white"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    tools:deviceIds="wear">

    <android.support.wear.widget.BoxInsetLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical"
            app:boxedEdges="left|top|right" >

            <TextView
                android:id="@+id/text_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/hello_world"
                android:textAlignment="center"
                android:textColor="@color/black"
                android:visibility="visible" />

        </LinearLayout>

    </android.support.wear.widget.BoxInsetLayout>

</ScrollView>

结果:
结果

期待:
![期待](https://ibb.co/vjPPmZR)

标签: androidandroid-layoutuser-interfacescrollwear-os

解决方案


解决方案是添加:android:fillViewport="true".


推荐阅读