2013-02-15 122 views
0

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

回答

0

更換

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