选择图库默认项是在中心是在、图库、中心

2023-09-13 00:15:18 作者:你瞎阿撞我心上了

可能重复:    Android的画廊图像位置

我用在我的应用程序库的看法。现在,当我运行code。画廊已经默认选择的项目没有1这是中心,左侧是一片空白。 相反,我想没有任何1个项目应在左边和选择。 同时点击任何库项目不应把该项目的中心。

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?

推荐答案

嘿,我还挺有围绕同样的问题,调整左边距像这样:

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;

如果您更换

-(metrics.widthPixels/2)

-(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)