gpt4 book ai didi

Android - 如何制作可滚动的约束布局?

转载 作者:IT老高 更新时间:2023-10-28 13:02:20 25 4
gpt4 key购买 nike

我想制作一个允许我使用约束布局向下滚动的布局,但我不知道该怎么做。 ScrollView 应该是 ConstraintLayout 这样的父级吗?

<?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">

<android.support.constraint.ConstraintLayout
android:id="@+id/Constraint"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

或者反过来呢?也许有人可以为我指出一个很好的教程或举个例子,我似乎找不到。

另外,我不知道这是一个错误还是一些我没有设置的配置,但我看到过这样的图像:

enter image description here

在蓝图“蓝色矩形”之外有一些组件但它们是可见的,而在我这边,如果我将组件放在“空白区域”上,我看不到它或将它移动到任何地方,它会出现在组件树。

更新:

我在设计工具中找到了一种使约束布局可滚动的方法,使用水平准线将约束布局边框下推并延伸到设备之外,之后,您可以将准线用作新的底部约束布局以锚定组件。

最佳答案

似乎它正在工作,我不知道您使用的是什么依赖项,但在这个中

compile 'com.android.support.constraint:constraint-layout:1.0.2'

正在工作,这就是我所做的

<?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"
tools:context=".MainActivity">

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.TextInputLayout
android:id="@+id/til_input"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Escriba el contenido del archivo"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/btn_save"
app:layout_constraintTop_toTopOf="@id/btn_save"
app:layout_constraintVertical_chainStyle="spread">

<EditText
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.TextInputLayout>

<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickButtonSave"
android:text="Guardar"
app:layout_constraintLeft_toRightOf="@+id/til_input"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/txt_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_input"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintVertical_weight="1" />

<Button
android:id="@+id/btn_delete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:onClick="onClickButtonDelete"
android:text="Eliminar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/txt_content"
app:layout_constraintVertical_chainStyle="spread" />

</android.support.constraint.ConstraintLayout>

</ScrollView>

滚动顶部 enter image description here

滚动底部 enter image description here

关于Android - 如何制作可滚动的约束布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43098150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com