Как создать слайд-меню в Xamarin. Android - PullRequest
0 голосов
/ 16 апреля 2020

Как создать слайд-меню в Xamarin. Android

enter image description here

1 Ответ

1 голос
/ 16 апреля 2020

Во-первых, создайте bottom_dialog. xml макет:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000"
    android:orientation="vertical"
    android:padding="16dp"
    app:behavior_hideable="false"
    app:behavior_peekHeight="90dp"
 app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

     <TextView

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:textColor="#fff"
        android:textSize="18"
        android:textAlignment="center"
        android:drawablePadding="20dp"
        android:text="Menu" />

    <TextView
        android:id="@+id/action1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:textColor="#fff"
        android:drawablePadding="16dp"
        android:text="111111111" />

    <TextView
        android:id="@+id/action2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:textColor="#fff"
        android:drawablePadding="16dp"  
        android:text="222222222" />

    <TextView
        android:id="@+id/action3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:textColor="#fff"
        android:drawablePadding="16dp"
        android:text="333333333" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:background="#aaa"
        android:text="Start"
        android:textColor="#fff" />

</LinearLayout>

И в активе

private void FabOnClick(object sender, EventArgs eventArgs)
{
   View dialogView = LayoutInflater.Inflate(Resource.Layout.bottom_dialog, null);
   BottomSheetDialog dialog = new BottomSheetDialog(this);
   dialog.SetContentView(dialogView);
   dialog.Show();
}

Обновление

Вы может переопределить метод OnTouchEvent в деятельности.

    float x1 = 0;
    float x2 = 0;
    float y1 = 0;
    float y2 = 0;


    public override bool OnTouchEvent(MotionEvent e)
    {



        if (e.Action==MotionEventActions.Down)
        {
            x1 = e.GetX();
            y1 = e.GetY();
        }

        if(e.Action == MotionEventActions.Up)
        {
            x2 = e.GetX();
            y2 = e.GetY();

            if(y1-y2>50)
            {
                View dialogView = LayoutInflater.Inflate(Resource.Layout.bottom_dialog, null);
                BottomSheetDialog dialog = new BottomSheetDialog(this);
                dialog.SetContentView(dialogView);
                dialog.Show();
            }


        }

        return base.OnTouchEvent(e);
    }

enter image description here

...