Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

how to change the stacklayout height dynamically? (equivalent to Wrap Content in Linear Layout)

$
0
0

Hi,

I have a stacklayout renderer and I am adding views in stacklayout. I want to wrap the stacklayout height as the added view content. Here is my renderer.

` public class ATabViewRenderer : Xamarin.Forms.Platform.Android.ViewRenderer<Xamarin.Forms.StackLayout, LinearLayout>
{

    private CustomTabView tabView;
    protected override void OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.StackLayout> e)
    {
        base.OnElementChanged (e);
        tabView = e.NewElement as CustomTabView;
        if (tabView != null) {
            tabView.DataPopulated += HandleDataPopulated;
            tabView.VerticalOptions = Xamarin.Forms.LayoutOptions.CenterAndExpand; // that doesnt work
            // tabView.HeightRequest = 150; this works but the height being static is not solutin for me
        }


    }

    void HandleDataPopulated(object sender, PanasonicMobile.Core.Models.Product e)
    {   //some code removed for clarity
        LinearLayout l = new LinearLayout (this.Context);
        l.Orientation = Orientation.Vertical;
        l.SetBackgroundColor(Color.Yellow);         
            TextView  Disclaimer = new TextView (this.Context);
        TextView  Heading = new TextView (this.Context);
        TextView  SubHeading = new TextView (this.Context);

         l.AddView (Heading);
         l.AddView (SubHeading);
         l.AddView (Disclaimer);

        SetNativeControl(l);

    }
}`

I tried also changing the height of the linear layout, but nothing helps.
If I set the tabView the heightreqeust ( tabView.HeightRequest = 150; ), it works. But static height is not the way of solution.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>