Divakar
Divakar

Reputation: 544

How to set padding/margin for the children inside a Linear Layout in Xamarin.Android?

I can able to set padding for linear layout. But I need to set padding for the children inside a linear layout. Please find my codes below,

    LinearLayout linear1 = new LinearLayout(BaseContext);
    TextView textView = new TextView(BaseContext);
    linear1.AddView(textView,100,100); (or) linear1.AddView(textView,LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
    SetContentView(linear1);

Now I need to set padding for the TextView loaded inside a linear layout. Is it possible?

Thanks in advance.

Upvotes: 1

Views: 547

Answers (2)

Divakar
Divakar

Reputation: 544

We can set padding for the children inside a linear layout like below,

LinearLayout linear1 = new LinearLayout(BaseContext);
    TextView textView = new TextView(BaseContext);
    linear1.AddView(textView,100,100);

            LinearLayout.LayoutParams options = (LinearLayout.LayoutParams)textView.LayoutParameters; //where textView is the view loaded inside a linear layout.
            options.LeftMargin = 30;
            options.TopMargin = 30;
            options.RightMargin = 30;
            options.BottomMargin = 30;

SetContentView(linear1);

Upvotes: 1

Jesse Jiang
Jesse Jiang

Reputation: 965

you can call linear1.SetPadding(int,int,int,int);

Upvotes: 0

Related Questions