gpt4 book ai didi

android - NestedScrollView 具有约束布局不滚动

转载 作者:太空狗 更新时间:2023-10-29 15:58:15 27 4
gpt4 key购买 nike

我的 xml 由一个约束布局组成。这里面有 2 个按钮和 1 个嵌套的 ScrollView 。 ScrollView 中有各种元素,包括回收 View 。我希望回收 View 不滚动,而只滚动嵌套的 ScrollView 。我在这种模式下禁用了回收 View 的滚动(recyclerView.setNestedScrollingEnabled(false);)但问题是嵌套 ScrollView 不滚动。你能帮助我吗?我附上下面的代码。

代码以这种模式开始:

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

<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<TextView
android:id="@+id/azzera"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginStart="40dp"
android:layout_marginBottom="28dp"
android:background="@drawable/rounded_4lati"
android:backgroundTint="@color/azzurro"
android:elevation="@dimen/dimen8"
android:paddingTop="@dimen/dimen8"
android:text="@string/azzera"
android:textAlignment="center"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/conferma"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="28dp"
android:background="@drawable/rounded_4lati"
android:backgroundTint="@color/azzurro"
android:paddingTop="@dimen/dimen8"
android:text="@string/conferma"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:elevation="@dimen/dimen8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
>

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

<View
android:id="@+id/view1"
android:layout_width="0dp"
android:layout_height="48dp"
android:background="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/view2"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:background="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/view1" />

<View
android:id="@+id/view3"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:background="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/view2" />

<TextView
android:id="@+id/mostraPreferiti"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:text="@string/mostraPreferiti"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/view3" />

<TextView
android:id="@+id/creditiEcm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:text="@string/creditiECM"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/view1" />

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:inputType="number"
android:hint="@string/zero"
android:text="@string/editText"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/creditiEcm"
app:layout_constraintTop_toTopOf="@+id/view1"
android:autofillHints="" />

<Button
android:id="@+id/buttonMeno"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="16dp"
android:background="@drawable/ic_remove_circle_azzurro_24dp"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="@color/azzurro"
android:textSize="24sp"
app:layout_constraintEnd_toStartOf="@+id/buttonPiu"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/buttonPiu"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="32dp"
android:background="@drawable/ic_add_circle_azzurro_24dp"
android:gravity="center"
android:textAlignment="gravity"
android:textColor="@color/azzurro"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/mostraCorsiPassati"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="@string/mostraCorsiPassati"
android:textColor="@color/black"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/view2"
app:layout_constraintTop_toTopOf="@+id/view2" />


<Switch
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:theme="@style/SwitchTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/view2" />

<Switch
android:id="@+id/switch_button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:theme="@style/SwitchTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/view3" />

<android.support.v7.widget.AppCompatTextView
android:id="@+id/professioni"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="90dp"
android:layout_marginEnd="8dp"
android:text="@string/professione2"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold"
app:fontFamily="@font/sanfrancisco"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mostraCorsiPassati" />


<SearchView
android:id="@+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:background="#fff"
android:elevation="2dp"
app:layout_constraintHorizontal_bias="0.557"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintRight_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/professioni"
app:queryHint="Cerca..">

</SearchView>

<android.support.v7.widget.RecyclerView
android:id="@+id/listProfessioni"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchBar"
android:orientation="vertical"
>


</android.support.v7.widget.RecyclerView>



<TextView
android:id="@+id/professioniNonDisponibili"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="@string/professioniNonDisponibili"
android:textAlignment="center"
android:textColor="@color/gray"
android:textSize="18sp"
app:autoSizeMaxTextSize="@dimen/dimen20"
app:autoSizeMinTextSize="@dimen/dimen12"
app:autoSizeTextType="uniform"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/error" />

<ImageView
android:id="@+id/error"
android:layout_width="@dimen/dimen80"
android:layout_height="@dimen/dimen80"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/ic_error_outline_gray_24dp"
android:contentDescription="@string/TODO"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/searchBar"
app:layout_constraintVertical_bias="0.105" />


<ProgressBar
android:id="@+id/progress"
android:layout_width="60dp"
android:layout_height="60dp"

android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:alpha="1"
android:minWidth="80dp"
android:minHeight="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/searchBar"
app:layout_constraintVertical_bias="0.168" />

</android.support.constraint.ConstraintLayout>


</android.support.v4.widget.NestedScrollView>

最佳答案

正如我在评论中的回答

对于其他面临同样问题的人。这可能会有所帮助。

由于某些原因,ScrollView 在包含 ConstraintLayout 时不会滚动。

对于解决方法,我们可以在 ScrollView 中使用 LinearLayoutRelativeLayout 而不是 ConstraintLayout。或者

由于 OP 确实将 ConstraintLayout 放在 Linear or Relative Layout 中,所以达到了目的。

关于android - NestedScrollView 具有约束布局不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52923818/

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