Friday, 16 August 2013

How do I get space between consecutive RelativeLayouts inside a LinearLayout?

How do I get space between consecutive RelativeLayouts inside a LinearLayout?

I'm trying to create a list of clickable image buttons w/ text that fit
inside a HorizontalScrollView. The images/content will be set
programmatically. The best way to do this seemed to be a LinearLayout,
that then contained a series of RelativeLayouts that contained the views
to display the relevant content. However, I'm having trouble getting space
between each RelativeLayout. Even though I've set margins in xml and
programmatically they seem to be ignored and the RelativeLayout objects
are squished together.
Some code:
<RelativeLayout
android:id="@+id/details_image_button"
android:layout_width="75dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:background="#00ff78">
<ImageView
android:id="@+id/loadable_image_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="@+id/details_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#b083ef"
android:text="PH - Info about title"
android:layout_alignParentBottom="true"
/>
//Code below is looped through several times
RelativeLayout imageButtonLayout = (RelativeLayout)
inflater.inflate(R.layout.details_image_button, null);
RelativeLayout.LayoutParams imageButtonLayoutParams = new
RelativeLayout.LayoutParams(100, 100);
imageButtonLayoutParams.setMargins(10, 10, 10, 10);
imageButtonLayout.setLayoutParams(imageButtonLayoutParams);
The current result that I am getting is a solid green (background color of
the RelativeLayout) rather than the expected result of a group of
RelativeLayouts with a space between each. How can I best get a margin or
buffer between each RelativeLayout?

No comments:

Post a Comment