Xamarin.Android:DrawerLayout.LayoutParams中的重力参数
作者:互联网
我正在尝试使用Xamarin.Android以编程方式创建DrawerLayout,但是在尝试添加应该从左侧拖动的ListView时遇到了问题.
这是我的代码:
DrawerLayout myDrawerLayout = new DrawerLayout(this);
myDrawerLayout.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
SetContentView(myDrawerLayout);
FrameLayout myFrameLayout = new FrameLayout(this);
myFrameLayout.LayoutParameters = new DrawerLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
myFrameLayout.SetBackgroundColor(Android.Graphics.Color.Gray);
myDrawerLayout.AddView(myFrameLayout);
ListView myListView = new ListView(this);
myListView.SetBackgroundColor(Android.Graphics.Color.Green);
myListView.LayoutParameters = new DrawerLayout.LayoutParams( width: 240,
height: DrawerLayout.LayoutParams.MatchParent,
gravity: ????????
);
myDrawerLayout.AddView(myListView);
如您所知..我不知道将什么作为重力参数传递
DrawerLayout类中的函数定义如下:
public LayoutParams(int width, int height, int gravity);
所以我必须通过int来获取引力,但是如何?
我尝试了以下方法:
myListView.LayoutParameters = new DrawerLayout.LayoutParams( width: 240, height: DrawerLayout.LayoutParams.MatchParent, gravity: Gravity.LEFT);
它给我错误:
‘Gravity’ does not contain a definition for ‘LEFT’
还尝试了:
myListView.LayoutParameters = new DrawerLayout.LayoutParams( width: 240, height: DrawerLayout.LayoutParams.MatchParent, gravity: GravityFlags.Left);
但给我一个错误:
cannot convert from ‘Android.Views.GravityFlags’ to ‘int’
希望您对解决方案有个了解..并在此先感谢
解决方法:
您必须将标志转换为int像
new DrawerLayout.LayoutParams(240, DrawerLayout.LayoutParams.WrapContent, (int)(GravityFlags.Start | GravityFlags.Left)).
标签:drawerlayout,android,xamarin-android,c-2 来源: https://codeday.me/bug/20191013/1906954.html