3

I've made fragment A fullscreen that overlay another fragment B. I want to handle the swipe touch that can close the fragment A swiping up and reopen it swiping down.

I've made this example image: enter image description here

How can I implement that? I've not found any tutorial of this particular case. Thank you.

Karen Forde
  • 1,117
  • 8
  • 20
Giacomo Lai
  • 494
  • 3
  • 15

2 Answers2

2

After several research, I've found a library that make implementation of sliding panels very easy.

It's the Umano Android Panel

Umano Android Panel repository

Giacomo Lai
  • 494
  • 3
  • 15
0

compile 'me.imid.swipebacklayout.lib:library:1.0.0'

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.darwich.swipetoclose.MainActivity">

    <RadioGroup
        android:id="@+id/id_radioGroup"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/mode_left"
            android:text="Left"
            android:textSize="24sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <RadioButton
            android:id="@+id/mode_right"
            android:text="Right"
            android:textSize="24sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <RadioButton
            android:id="@+id/mode_bottom"
            android:text="Bottom"
            android:textSize="24sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <RadioButton
            android:id="@+id/all"
            android:text="All"
            android:textSize="24sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </RadioGroup>

</RelativeLayout>
public class MainActivity extends SwipeBackActivity {

    private SwipeBackLayout swipeBackLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        RadioGroup trackingModeGroup = (RadioGroup) findViewById(R.id.id_radioGroup);
        swipeBackLayout = getSwipeBackLayout();

        trackingModeGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int edgeFlag;
                switch (checkedId) {
                    case R.id.mode_left:
                        edgeFlag = SwipeBackLayout.EDGE_LEFT;
                        break;
                    case R.id.mode_right:
                        edgeFlag = SwipeBackLayout.EDGE_RIGHT;
                        break;
                    case R.id.mode_bottom:
                        edgeFlag = SwipeBackLayout.EDGE_BOTTOM;
                        break;
                    default:
                        edgeFlag = SwipeBackLayout.EDGE_ALL;
                }
                swipeBackLayout.setEdgeTrackingEnabled(edgeFlag);
            }
        });
    }
}