我想制作串列視圖,允許用戶在不點擊串列項的情況下選擇選項,將通過類似于堆疊的滑動手勢選擇專案。 在此處輸入圖片描述查看
如此影像串列中給出的將像滾動一樣移動(通過滑動更改選項)以避免拿起手指
請告訴我您是否在 android 中找到任何庫或小部件或任何其他方式
uj5u.com熱心網友回復:
創建 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>
uj5u.com熱心網友回復:
我找到了答案
在activity_main.xml中
<?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>
然后在
activity_main_scene.xml
<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 中不需要額外的更改
我在這里找到了這個
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/341087.html
上一篇:std::vector和移動語意
