0

enter image description hereI have a set of images to be added. I have to place one image in first row and the images in second row should start at the end of first row image

How can I achieve it with linearlayout in xamrin android?

Bhargavi
  • 184
  • 12

1 Answers1

0

Do you want to achieve it like following screenshot. enter image description here

If so, you could used linearLayout.SetPaddingRelative(imageView1.Drawable.IntrinsicWidth, 0,0,0); to set the start of padding in following linearlayout.

there is my code.

 protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.activity_main);
        LinearLayout ll_layout = FindViewById<LinearLayout>(Resource.Id.ll_layout);

        LinearLayout linearLayout1 = new LinearLayout(this);


        ImageView imageView1 = new ImageView(this);
        imageView1.SetImageResource(Resource.Drawable.Capture1);
        linearLayout1.AddView(imageView1);
        ll_layout.AddView(linearLayout1);

        LinearLayout linearLayout2 = new LinearLayout(this);
        linearLayout2.SetPaddingRelative(imageView1.Drawable.IntrinsicWidth, 0,0,0);
        ImageView imageView2 = new ImageView(this);
        imageView2.SetImageResource(Resource.Drawable.Capture2);
        linearLayout2.AddView(imageView2);
        ll_layout.AddView(linearLayout2);



    }
Leon
  • 8,404
  • 2
  • 9
  • 52
  • https://stackoverflow.com/users/10627299/leon-lu-msft Hey Thanks. I get to know about SetPaddingRelative. – Bhargavi Jan 30 '19 at 05:53
  • https://stackoverflow.com/users/10627299/leon-lu-msft But my problem is not exactly this. I have updated my question with attaching a sample image of what I need. How can I calculate the X & Y and fill them with empty views – Bhargavi Jan 30 '19 at 06:02
  • You could use `getLocationOnScreen()` to get the X ,Y location of this control in the screen. https://stackoverflow.com/questions/17672891/getlocationonscreen-vs-getlocationinwindow .Based on your screenshot, the value of Y is your control's height. – Leon Jan 30 '19 at 07:55