Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gallery default item selected is in center [duplicate]

Possible Duplicate:
android gallery image position problem

I'm using Gallery view within my app. Now when I run the code. Gallery has default selected item is no 1 which is in center and left side is blank. Instead I want no 1 item should be at left and selected. Also clicking on the any gallery item should not bring that item in the center.

I tired hunting it lot on the groups but not found any solution. Is this possible or not ? If yes then how come?

like image 925
Umakant Patil Avatar asked Mar 23 '11 11:03

Umakant Patil


1 Answers

hey, I kinda got around the very same issue with adjusting the left margin like so:

DisplayMetrics metrics = new DisplayMetrics();
ctx.getWindowManager().getDefaultDisplay().getMetrics(metrics);

Gallery gallery = (Gallery) ctx.findViewById(R.id.gallery);

MarginLayoutParams mlp = (MarginLayoutParams) gallery.getLayoutParams();
mlp.setMargins(-(metrics.widthPixels/2), 
               mlp.topMargin, 
               mlp.rightMargin, 
               mlp.bottomMargin
);

which goes almost to the left edge, but there is a bit of slack (half image width?), which I actually liked;

if you replace

-(metrics.widthPixels/2)

with

-(metrics.widthPixels/2 + YOUR_IMAGE_WIDTH)

it goes all the way to left edge of the screen (provided this gallery is displaying images of same size, which was my case)

like image 197
gibffe Avatar answered Oct 21 '22 04:10

gibffe