图库图片是从Android图库中心启动
在我的XML file.In画廊看到下面我有两个按钮间画廊,图像从中心加入。
I am having gallery in between two buttons as seen below in my xml file.In Gallery, images are adding from the center.
<RelativeLayout
android:layout_height="80dp"
android:layout_width="fill_parent"
android:id="@+id/gal"
android:layout_alignParentBottom="true"
android:background="@drawable/backgroundblackwhite">
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/backward"
android:layout_alignParentLeft="true"/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/forward"
android:layout_alignParentRight="true"/>
<Gallery
android:layout_height="100dp"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:id="@+id/gallary"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
android:spacing="5dp"
android:layout_marginBottom="10dp"
android:background="@drawable/greypattren"/>
</RelativeLayout>
I want the images to start from Left of my Gallery.I used the below code to set the gallery images start from left of gallery view.
DisplayMetrics指标=新DisplayMetrics();
。getWindowManager()getDefaultDisplay()getMetrics(指标);
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
Gallery g = (Gallery) findViewById(R.id.gallery);
// set gallery to left side
MarginLayoutParams mlp = (MarginLayoutParams) g.getLayoutParams();
mlp.setMargins(-(metrics.widthPixels / 2 + (imageWidth/2)), mlp.topMargin,
mlp.rightMargin, mlp.bottomMargin);
不过,我的画廊将最左边即躲在我的左按钮(这是我应该使用滚动图库)
But,my Gallery is going to the extreme left i.e hiding my Button in the left(which I should use for scrolling Gallery)
我张贴两个图像的截图,
1)图库视图,我想,我要的影像,从屏幕左侧的添加。
2)将上述code。使用指标(设置页边距)后,画廊改变。
I am posting the Screenshots of both the images, 1)The Gallery View which I want,and I want the images to add from left of the screen. 2)Changing of Gallery after adding the above code(setting the margins) using metrics.
难道我需要在XML或code改变什么?
Did I need to change anything in xml or code?
请帮忙
在此先感谢
please help Thanks in advance
替换
MarginLayoutParams mlp = (MarginLayoutParams) g.getLayoutParams();
mlp.setMargins(-(metrics.widthPixels / 2 + (imageWidth/2)), mlp.topMargin,
mlp.rightMargin, mlp.bottomMargin);
要
mlp.setMargins((int) -(metrics.widthPixels/2.5), mlp.topMargin, mlp.rightMargin, mlp.bottomMargin);