简体   繁体   中英

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:

    linlay.LayoutParameters = _params;

Why is that?

Thank you!

I just stumbled upon the solution: appearently, the layoutparams have to be of the parent. 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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