首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LinearLayout和NestedScrollView问题

LinearLayout和NestedScrollView问题
EN

Stack Overflow用户
提问于 2021-01-22 20:38:17
回答 1查看 66关注 0票数 1

我想如何使用NestedScrollView,顶部的工具栏视图和底部的底部视图。顶视图、底视图、工具栏和底视图必须始终处于适当位置。

如何在任何设备上实现此结果?感谢您的回复,谢谢。

总是这样:

这是我的代码:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical">
    <!--This is top-->
    <androidx.appcompat.widget.LinearLayoutCompat
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="@color/colorPrimary">
        <!--.........................-->
    </androidx.appcompat.widget.LinearLayoutCompat>


    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="@color/colorGreyFragment">
            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </androidx.constraintlayout.widget.ConstraintLayout>
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

    <!--This is bottom-->
    <androidx.appcompat.widget.LinearLayoutCompat
        android:id="@+id/bottom_buttons_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center"
        android:background="@color/colorWhite">
        <!--..............................-->
    </androidx.appcompat.widget.LinearLayoutCompat>

</LinearLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-22 20:46:33

你可以这样做,

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical">
    <!--This is top-->
    <androidx.appcompat.widget.LinearLayoutCompat
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="@color/colorPrimary">
        <!--.........................-->
    </androidx.appcompat.widget.LinearLayoutCompat>


    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorGreyFragment"
            android:orientation="vertical">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"></androidx.constraintlayout.widget.ConstraintLayout>
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

    <!--This is bottom-->
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

我已经用BottomNavigationView替换了你在底部的线性布局,如果你想要其他的东西,你可以在那里替换。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65845360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档