I want to align GridView in center
still i am getting like this:
As you can see in above image, i am getting images on left hand side, but i want to show images in center like below:
another thing getting extra width of text background How can i show text background within image only
now gridview is in center, but still getting issue, see text background huge width which is going out of imageview:
Please check updated xml script
activity_main.xml:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/header_bg"
android:gravity="center"
android:text="@string/header_main"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
>
<GridView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:columnWidth="@dimen/photo_size"
android:horizontalSpacing="@dimen/photo_spacing"
android:numColumns="4"
android:gravity="center"
android:padding="4dp"
android:scrollbars="none"
android:stretchMode="columnWidth"
android:layout_gravity="center"
android:verticalSpacing="@dimen/photo_spacing" />
</LinearLayout>
</RelativeLayout>
row.xml:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/album_item"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/cover"
android:contentDescription="@string/app_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:layout_alignBottom="@+id/cover"
android:background="#70000000"
android:gravity="center"
android:padding="6dp"
android:textColor="@color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
and if i use TextView as wrap_content
then getting like this: