小编OPW*_*agg的帖子

如何使用导航组件找出前一个片段的内容

我试图找出前一个片段在 backstack 中的内容,如果它是我想要的片段,则返回到那个片段,否则转到另一个片段。我在查找之前片段的名称/ID 时遇到问题。我目前的设置如下:

Fragment 1 -> Fragment 2 -> Fragment 3 如果 Fragment 3 的前一个 id 是 >Fragment 2,则返回它并带参数。

但我也会遇到这种情况:

Fragment 4 -> Fragment 3 这里我还希望能够检查 Fragment 3 的前一个 id/name 是否等于 Fragment 4,以及它是否返回到带有参数的 Fragment。

基本上片段 3 会有不同的路径,我希望能够确定它接下来将转到哪个前一个片段。

我的问题是我无法访问以前 Fragments 的信息。检查是否有任何可能。我是使用 Android 导航组件的新手,因此不胜感激。

如果问题看起来有点令人困惑,请告诉我,以便我可以在需要时重写它。

谢谢!

android android-fragments kotlin android-navigation

8
推荐指数
1
解决办法
1585
查看次数

当视图限制为卡片视图时,如何修复视图从页面关闭的问题

我最近通过一个android项目将其转换为androidx,并且在尝试阻止页面上的视图出现问题。我的布局如下,其中包含Card View和Text View的Constraint Layout。在此卡片视图中,我有一个包含文本视图的约束布局。在“卡片视图”之外,我有一个受“卡片视图”约束的按钮。

这样做的问题是,当我运行该程序时,“卡片视图”将从屏幕上移开,并且即使所有按钮都受到适当限制,按钮也会一直移动到顶部。

我将在下面显示用于实现此目的的代码以及在模拟器上的结果图像。

这是编辑器[1]中的布局:https : //imgur.com/a/0FLa1IK

这是仿真器[2]上显示的布局:https : //imgur.com/a/SsvKiOG

任何帮助将不胜感激。

<androidx.constraintlayout.widget.ConstraintLayout 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">

    <androidx.cardview.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/materialButton"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

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

            <TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="16dp"
                android:text="Text View Test"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

    <Button
        android:id="@+id/materialButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="256dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Run Code Online (Sandbox Code Playgroud)

java android android-cardview android-constraintlayout

6
推荐指数
1
解决办法
72
查看次数