gpt4 book ai didi

c# - Xamarin.Android : Gravity parameter in DrawerLayout. 布局参数

转载 作者:太空宇宙 更新时间:2023-11-03 19:51:21 24 4
gpt4 key购买 nike

我正在尝试使用 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);

如您所见..我不知道要传递什么作为gravity参数

DrawerLayout 类中函数的定义是这样的:

public LayoutParams(int width, int height, int gravity);

所以我必须为 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)).

关于c# - Xamarin.Android : Gravity parameter in DrawerLayout. 布局参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39012568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com