
我在两个按钮之间有一个图库,如下面的xml文件所示。在画廊中,图像是从中心添加的。
<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 to start from the left of gallery view.新指标= DisplayMetrics 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);但是,我的图库在最左边,即在左边隐藏我的按钮(我应该用它来滚动图库)
我张贴两个图像的截图,1)画廊视图,我想从屏幕的左边添加图像。2)使用指标添加上述代码(设置边距)后,对图库进行更改。
我需要更改xml或代码中的任何内容吗?
请提前帮个忙谢谢

发布于 2013-02-15 19:35:12
替换
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);https://stackoverflow.com/questions/14891776
复制相似问题