滚动位置出现问题(嵌套滚动视图)

时间:2020-02-26 10:49:31

标签: android position android-nestedscrollview

说明:

我正在创建类似“ Duolingo”的应用。我有一项活动希望您看到:

enter image description here

可以看到约束布局,其中具有带有“后退”箭头的图像视图和带有“惯用语”的文本视图。然后,您将看到另一个名为“ Opciones”的文本视图(不受限制),以及下面的棕线。最后,在所有内部都有回收者视图的片段之间交换框架布局。如您在ive随附的图片中看到的那样,这些回收者视图具有国家标志。

问题:

当我参加活动时,(嵌套滚动的)滚动位置在棕线的正下方。我附上另一张有关这种情况的照片:

enter image description here

我想当我参加活动时,滚动位置是x:0 y:0,就像您看到照片 1号一样。

我已经尝试过此操作,但是它根本不起作用(请问为什么)

NestedScrollView nested = findViewById(R.id.nested);
nested_categorias.scrollTo(0,0);

我正在附加活动的XML代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
android:id="@+id/nested"
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"
tools:context="com.example.ui.INICIO.CATEGORIAS.categorias"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/ayuda">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/ayuda">

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/constraint_bar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:elevation="4dp"
    android:contentDescription="@string/ayuda"
    android:background="#8d6e63"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <ImageButton
        android:id="@+id/imgbt_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:background="?selectableItemBackgroundBorderless"
        android:contentDescription="@string/ayuda"
        android:src="@drawable/icon_back_negro"
        android:tint="#ffffff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/txt_categoria"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="15dp"
        android:contentDescription="@string/ayuda"
        android:text="Idiomas"
        android:textColor="#ffffff"
        android:textSize="15.5sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="@+id/imgbt_back"
        app:layout_constraintStart_toEndOf="@+id/imgbt_back"
        app:layout_constraintTop_toTopOf="@+id/imgbt_back" />

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
    android:id="@+id/txt_opciones"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:contentDescription="@string/ayuda"
    android:fontFamily="@font/roboto"
    android:text="@string/opciones"
    android:textColor="#795548"
    android:textSize="16sp"
    android:textStyle="bold"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/constraint_bar"/>

<TextView
    android:id="@+id/txt_barra1"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="5dp"
    android:background="#6d4c41"
    android:contentDescription="@string/ayuda"
    android:gravity="center"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/txt_opciones" />

<FrameLayout
    android:id="@+id/fragment_idiomas"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:contentDescription="@string/ayuda"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/txt_barra1" />

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>

我该怎么办?

非常感谢您的阅读!

0 个答案:

没有答案