Reputation: 3362
I'm using gallery in android for showing images. My question is how can i set the margins of the imageViews inside the gallery, so that they are not right next to each other but rather have some space between them.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Gallery
android:id="@+id/glr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
<ImageView
android:id="@+id/imageView1"
android:layout_marginTop="100dp"
android:layout_width="250dp"
android:layout_gravity="center_horizontal"
android:layout_height="250dp" />
</LinearLayout>
and this is my how i set the imageView in the gallery:
public View getView(int index, View view, ViewGroup viewGroup)
{
ImageView i = new ImageView(mContext);
i.setImageBitmap(photos[index]);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(50, 50, 50, 50);
i.setLayoutParams(params);
return i;
}
Upvotes: 1
Views: 611
Reputation: 3362
finnally it isn't possible to do so in a gallery got to make your own implementation
Upvotes: 1
Reputation: 1621
You can do it programmatically when setting the images like this:
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(left, top, right, bottom);
imageView.setLayoutParams(params);
Upvotes: 0