How to make space between LinearLayout children?

后端 未结 13 563
一整个雨季
一整个雨季 2020-11-30 23:46

I am programatically adding custom views to a vertical LinearLayout, and I would like there to be some space between the views. I have tried adding: setPadding(0, 1, 0, 1)

13条回答
  •  温柔的废话
    2020-12-01 00:35

    An easy way to do it dynamically is to add padding to the children. You can just set it using .setPadding() on the object to be added. This example is adding an ImageView to a LinearLayout:

    LinearLayout userFeedLinearLayout = (LinearLayout) findViewById(R.id.userFeedLinearLayout);
    imageView.setImageBitmap(bitmap);
    imageView.setPadding(0, 30, 0, 30);
    userFeedLinearLayout.addView(imageView);
    

    The following image shows two ImageViews that have been added with padding:

提交回复
热议问题