画廊图像是从画廊的中心安卓

问题描述:

enter image description here画廊图像是从画廊的中心安卓

开始我有所见低于我的XML file.In画廊,图像从中心将在按钮两者之间的画廊。

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

但是,我的画廊是要极左即躲在我的按钮在左侧(我应该滚动画廊使用)

我张贴的截图两个图像, 1)我想要的图库视图,我希望从屏幕左侧添加图像。 2)使用指标添加上面的代码(设置边距)后更改图库。

我是否需要更改xml或代码中的任何内容?

请帮助 在此先感谢

enter image description here

+0

嗨你得到答案? – gowri 2013-09-12 11:48:31

更换

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); 
+0

不工作,我得到同样的问题 – user1891910 2013-02-15 13:19:49