图库视图不是从左侧开始

Jig*_*iya 4 android android-gallery

我正在使用这样的画廊

<Gallery
    android:id="@+id/gallery1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:spacing="2dp" >
</Gallery>
Run Code Online (Sandbox Code Playgroud)

但是当我运行代码时,我发现画廊从中间开始,我想从左边开始.我应该怎么做才能帮助我.

小智 7

描述有关显示的一般信息的结构,例如其大小,密度和字体缩放.要访问DisplayMetrics成员,请初始化此类对象

        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);
Run Code Online (Sandbox Code Playgroud)