简体   繁体   English

Xamarin.Android如何在C#中以编程方式没有图像的线性布局和空白区域中添加图像?

[英]How to add images in a linear layout and empty spaces where there is no images programatically in C#?Xamarin.Android

enter image description here I 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? 如何在Xamrin android中使用linearlayout实现它?

Do you want to achieve it like following screenshot. 您是否想像下面的截图那样实现它。 在此处输入图片说明

If so, you could used linearLayout.SetPaddingRelative(imageView1.Drawable.IntrinsicWidth, 0,0,0); 如果是这样,则可以使用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);



    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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