Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gallery view is not starting from left

I am using Gallery like this

<Gallery
    android:id="@+id/gallery1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:spacing="2dp" >
</Gallery>

but when I am running the code I am finding gallery starting from middle and I want to start it from left. what should I do for this please help me.

like image 294
Jignesh Ansodariya Avatar asked Dec 17 '22 01:12

Jignesh Ansodariya


2 Answers

A structure describing general information about a display, such as its size, density, and font scaling.To access the DisplayMetrics members, initialize an object like this

        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);
like image 184
anupam sharma Avatar answered Jan 06 '23 08:01

anupam sharma


just set the selection of Gallery to next, which resemble that gallery is in Left position.

Gallery mGallery= (Gallery) findViewById(R.id.gallery);
mGallery.setSelection(1);

then continue with your normal work :)

like image 22
Mohammed Azharuddin Shaikh Avatar answered Jan 06 '23 10:01

Mohammed Azharuddin Shaikh