如何在Xamarin.Android中创建幻灯片菜单
如何在Xamarin.Android中创建幻灯片菜单如何在Xamarin.Android中创建幻灯片菜单,xamarin.android,Xamarin.android,如何在Xamarin.Android中创建幻灯片菜单 首先,创建一个底部对话框.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" a
首先,创建一个底部对话框.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>
使现代化
您可以覆盖活动中的方法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);
}
非常感谢。Lucas Zhang有没有办法让菜单消失,当你从下往上拉时,会再次出现。你可以添加一个滑动事件并调用上述代码。从上往上拉的事件名称是什么
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);
}