I have this code
View item = View.inflate(context, R.layout.item_layout, null);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
layout.addView(item, params);
my item_layout: (note the part android:layout_marginTop="2dip")
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_marginTop="2dip" android:layout_width="fill_parent">
<ImageView android:src="@drawable/pic_unknown" android:id="@+id/image1"
android:layout_height="50dip" android:layout_width="50dip"
android:padding="5dip"></ImageView>
</RelativeLayout>
and then in my layout I see the list of items inflated but with no margin in-between them. I tried with margintop=10dip still nothings happen my point is that the value I put in the layout it is not taken in the calculation with or without the margin top the layout is the same.
How can I add some empty space between the items ? How can I inflate a empty space between the items ? Is it possible to inflate something like gap or some space ? or I must use workaround like inflating some empty layout with 2dip height or something Thanks
"Inflating" a view means taking the layout XML and parsing it to create the view and viewgroup objects from the elements and their attributes specified within, and then adding the hierarchy of those views and viewgroups to the parent ViewGroup.
The LayoutInflater class is used to instantiate the contents of layout XML files into their corresponding View objects. In other words, it takes an XML file as input and builds the View objects from it.
As the title says, this post deals with LayoutInflater in Android and its most common usage with the inflate method. This method is used to create a view object from an XML file (where the UI designs are created). Then, you can have this view show up wherever you want (of course, in your app, not your freezer 😋).
You can specify your own custom margin settings. Click Margins, click Custom Margins, and then in the Top, Bottom, Left, and Right boxes, enter new values for the margins.
The last parameter of the inflate method is the parameter to which you add the inflated view. In your case it is null
. Try this instead:
View item = View.inflate(context, R.layout.item_layout, layout);
Try Padding the RelativeLayout instead if your margins apply to the outside.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With