0

ここに画像の説明を入力

以下のxmlファイルにあるように、2つのボタンの間にギャラリーがあります。ギャラリーでは、画像が中心から追加されています。

<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(メトリックス);

            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 またはコードを変更する必要がありましたか?

助けてください よろしくお願いします

ここに画像の説明を入力

4

1 に答える 1

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);
于 2013-02-15T11:35:12.493 に答える