您如何在ScrollView中将ConstraintLayout添加到适合整个屏幕的LinearLayout中?

问题描述 投票:0回答:2

我希望能够在LinearLayout中滚动,其中每个元素都是适合整个屏幕的ConstraintLayout。

我在每个Layout中都尝试了layout_height的多个值,但似乎没有任何效果。我可以在适合我的屏幕的layout_height中进行硬编码,但这并不理想。

这是我目前拥有的:

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </androidx.constraintlayout.widget.ConstraintLayout>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </androidx.constraintlayout.widget.ConstraintLayout>
    </LinearLayout>
</ScrollView>

这是产生的设计:

enter image description here

尽管设计看起来像我想要的样子,但我无法向下滚动以查看后续的ConstraintLayout。

非常感谢您的帮助。我已经在网上搜索过,并试图修复了数小时却无结果]

我希望能够在LinearLayout中滚动,其中每个元素都是适合整个屏幕的ConstraintLayout。我已经尝试过在每个布局中为layout_height设置多个值,但似乎什么都没有...

android android-linearlayout android-constraintlayout android-scrollview
2个回答
0
投票

您实际上想要哪种类型?您可以分享一些屏幕截图吗?


0
投票

确定,非常简单。您不能在xml上执行此操作,而必须在代码中执行。下面的第一个create类:

© www.soinside.com 2019 - 2024. All rights reserved.