I wanted to make List view which allow user to select option without tap on List Item, item will be selected by swipe gesture similar to stack. enter image description hereView
as given in this image list will move like scroll (changes option with swipe) to avoid picking up finger
Please tell me if you find any libary or widget or any other way in android
CodePudding user response:
create listview or recyclerview and must create selector for background items() when clicked item in adapter.
this is an example selector for edittext when focused
<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>
CodePudding user response:
I found the answer
In 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>
then in
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>
there is no additional changes is needed in java or in kotline
I found this in here