我如何可以设置code-背后保证金MonoDroid的? [英] How can I set Margin in Code-behind for MonoDroid?
问题描述
这个问题很简单,但我没有找到一无所知。如何设置保证金成widget在code-落后。
我发现这个文件到<一个href=\"http://androidapi.xamarin.com/?link=M%3aAndroid.Views.ViewGroup%2bMarginLayoutParams.SetMargins%28System.Int32,System.Int32,System.Int32,System.Int32%29\"相对=nofollow> Xamarin的网站,但我不能用这个进入的ImageView
我也试过在我的ImageView的方法布局(),但没有奏效。
ImageView的imgView = FindViewById&LT; ImageView的&GT;(Resource.Id.imageView);
imgView.Layout(10,10,10,10);
您是否尝试过使用的FrameLayout的的LayoutParams?
下面是一个例子:
您的图像:
ImageView的imgView = FindViewById&LT; ImageView的&GT;(Resource.Id.imageView);
您图像的参数:
FrameLayout.LayoutParams imgViewParams =新FrameLayout.LayoutParams(FrameLayout.LayoutParams.WrapContent,FrameLayout.LayoutParams.WrapContent,0.0);
imgViewParams.SetMargins(10,10,10,10);
设置图片的参数:
imgView.LayoutParameters = imgViewParams;
编辑:改变的LinearLayout .LayoutParameters为的FrameLayout .LayoutParameters
this question is simple, but i'm not finding nothing about it. How can i set margin into a widget in code-behind.
I found this document into Xamarin's site, but i can't use this into a ImageView
I also tried the method Layout() in my ImageView, but it didn't work.
ImageView imgView = FindViewById<ImageView>(Resource.Id.imageView);
imgView.Layout(10, 10, 10, 10);
Have you tried using FrameLayout's LayoutParams?
Here is an example:
Your image:
ImageView imgView = FindViewById<ImageView>(Resource.Id.imageView);
Your image's parameters:
FrameLayout.LayoutParams imgViewParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WrapContent, FrameLayout.LayoutParams.WrapContent, 0.0f);
imgViewParams.SetMargins(10, 10, 10, 10);
Setting your image's parameters:
imgView.LayoutParameters = imgViewParams;
EDIT: Changed LinearLayout.LayoutParameters to FrameLayout.LayoutParameters!
这篇关于我如何可以设置code-背后保证金MonoDroid的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!