我想制作列表视图,允许用户在不点击列表项的情况下选择选项,项目将通过类似于堆栈的滑动手势来选择。 在此处输入图像描述查看
如此图像列表中所示,将像滚动一样移动(通过滑动更改选项)以避免拿起手指
如果您在 android 中找到任何库或小部件或任何其他方式,请告诉我
我想制作列表视图,允许用户在不点击列表项的情况下选择选项,项目将通过类似于堆栈的滑动手势来选择。 在此处输入图像描述查看
如此图像列表中所示,将像滚动一样移动(通过滑动更改选项)以避免拿起手指
如果您在 android 中找到任何库或小部件或任何其他方式,请告诉我
创建 listview 或 recyclerview 并且必须在单击适配器中的项目时为背景项目()创建选择器。
这是聚焦时编辑文本的示例选择器
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="6dp" />
<stroke android:width="1dp" android:color="@color/primary" />
</shape>
</item>
<item android:state_enabled="true">
<shape android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="6dp" />
<stroke android:width="1dp" android:color="@color/gray" />
</shape>
</item>
我找到了答案
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<androidx.constraintlayout.motion.widget.MotionLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/motionLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/activity_main_scene"
tools:showPaths="true">
<LinearLayout
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Not Required"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="not Recieved"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Partially Recieved"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Recieved"
android:gravity="center"
/>
</LinearLayout>
<View
android:id="@+id/view"
android:layout_width="300dp"
android:layout_height="50dp"
android:background="@drawable/rectangle"
/>
</androidx.constraintlayout.motion.widget.MotionLayout>
</FrameLayout>
然后在
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetStart="@+id/first"
motion:constraintSetEnd="@+id/second"
motion:duration="10">
<OnSwipe
motion:touchAnchorId="@+id/button"
motion:dragDirection="dragUp"
/>
</Transition>
<Transition
motion:constraintSetStart="@+id/second"
motion:constraintSetEnd="@+id/third"
motion:duration="10">
<OnSwipe
motion:touchAnchorId="@+id/button"
motion:dragDirection="dragUp"
/>
</Transition>
<Transition
motion:constraintSetStart="@+id/third"
motion:constraintSetEnd="@+id/fourth"
motion:duration="10">
<OnSwipe
motion:touchAnchorId="@+id/button"
motion:dragDirection="dragUp"
/>
</Transition>
<ConstraintSet android:id="@+id/first">
<Constraint
android:id="@+id/button"
android:layout_width="300dp"
android:layout_height="200dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="@id/view"
android:layout_marginTop="0dp"
>
<CustomAttribute
motion:attributeName="BackgroundColor"
motion:customColorValue="#ddd" />
</Constraint>
<Constraint
android:id="@+id/view"
android:layout_width="300dp"
android:layout_height="50dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/second">
<Constraint
android:id="@+id/button"
android:layout_width="300dp"
android:layout_height="200dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="@id/view"
android:layout_marginTop="-50dp">
<CustomAttribute
motion:attributeName="BackgroundColor"
motion:customColorValue="#ddd" />
</Constraint>
<Constraint
android:id="@+id/view"
android:layout_width="300dp"
android:layout_height="50dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/third">
<Constraint
android:id="@+id/button"
android:layout_width="300dp"
android:layout_height="200dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="@id/view"
android:layout_marginTop="-100dp">
<CustomAttribute
motion:attributeName="BackgroundColor"
motion:customColorValue="#ddd" />
</Constraint>
<Constraint
android:id="@+id/view"
android:layout_width="300dp"
android:layout_height="50dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/fourth">
<Constraint
android:id="@+id/button"
android:layout_width="300dp"
android:layout_height="200dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="@id/view"
android:layout_marginTop="-150dp">
<CustomAttribute
motion:attributeName="BackgroundColor"
motion:customColorValue="#ddd" />
</Constraint>
<Constraint
android:id="@+id/view"
android:layout_width="300dp"
android:layout_height="50dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>
</MotionScene>
在 java 或 kotline 中不需要额外的更改
我在这里找到了这个