简体   繁体   English

Xamarin,Android:以编程方式更改线性布局的大小

[英]Xamarin, Android: Change size of linear Layout programmatically

here is my code: 这是我的代码:

        linlay = FindViewById<LinearLayout>(Resource.Id.linlay_profile);
        LinearLayout.LayoutParams _params = new LinearLayout.LayoutParams
            (500, 500);
        linlay.LayoutParameters = _params;

So, in my xml, there is a linearlayout with a height 0f 200. Now, in the programcode I need to change the height to 500. But it crashes on the last bit of code: 因此,在我的xml中,有一个高度为0f 200的linearlayout。现在,在程序代码中,我需要将高度更改为500。但是它在最后的代码上崩溃:

    linlay.LayoutParameters = _params;

Why is that? 这是为什么?

Thank you! 谢谢!

I just stumbled upon the solution: appearently, the layoutparams have to be of the parent. 我偶然发现了解决方案:显然,layoutparams必须是父级的。 in my case this was a framelayout. 就我而言,这是一个框架布局。 dont get it either but its working now. 也没有得到它,但现在可以正常工作了。

        linlay = FindViewById<LinearLayout>(Resource.Id.linlay_profile);
        FrameLayout.LayoutParams _params = new FrameLayout.LayoutParams
            (ViewGroup.LayoutParams.FillParent, 
            (Resources.DisplayMetrics.HeightPixels / 3));
        linlay.LayoutParameters = _params;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM