question

njsokalski avatar image
0 Votes"
njsokalski asked RobCaplan edited

Setting layout_column & layout_row in Codebehind

This is probably one of the most straightforward questions with one of the most straightforward answers I will ever ask, but here it is. I have a GridLayout with several children for which I need to modify the layout_column and/or layout_row properties (I want everything else to stay as it is in the xml layout file). Everything I have been able to find talks about LayoutParams & spec. I can see LayoutParams in Visual Studio 2019 intellisense, but nothing in it seems to match or work the way the examples say, and I cannot find anything called spec. How do I change the layout_column and/or layout_row values in Xamarin.Android codebehind? Thanks.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered

Hello,​

Welcome to our Microsoft Q&A platform!

I need to modify the layout_column and/or layout_row properties

For this function, try the following code.

var layout = FindViewById<GridLayout>(Resource.Id.layout);
var text = FindViewById<TextView>(Resource.Id.text);
GridLayout.Spec rowSpec = GridLayout.InvokeSpec(1);
GridLayout.Spec columnSpec = GridLayout.InvokeSpec(1);
GridLayout.LayoutParams paramsss = new GridLayout.LayoutParams(rowSpec, columnSpec); 
text.LayoutParameters = paramsss;


Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.