I have 3 columns GridViewand 4 elements.
It so happened that three of them appear in the first line, and the last in the second line, but this is aligned to the left. I just wanted to know if it was possible to center it in GridView. Like a T, I donβt know if I will explain ... xD
Thank: -)
Edit:
This is a layout containing GridView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/section_title_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_gd_home_grid">
<ImageView
android:src="@drawable/home_grid_txori"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:layout_centerHorizontal="true"/>
<GridView
android:id="@+id/home_grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:numColumns="3"
android:drawSelectorOnTop="true"
android:layout_marginBottom="30dip"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:padding="5dip"
android:listSelector="@android:color/transparent"
android:background="@drawable/bg_home_grid_item"
/>
</RelativeLayout>
By the way, android:layout_centerHorizontal="true"does not work in GridView
Decision:
This is a problem from past years, but I was asked to post a solution, and I had to find my old repo to get it :-)
As I said in the comments, I could not achieve this only in XML format, so I had to trick a fake non-switchable + inaccurate element in third position.
, "ViewHolder".
getView() :
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = (RelativeLayout) mInflater.inflate(
R.layout.home_grid_item, null);
}
if (position == 3) {
convertView.setFocusable(false);
convertView.setClickable(false);
} else {
ImageView imageView = (ImageView) convertView
.findViewById(R.id.image);
imageView.setImageResource(mThumbs[position]);
TextView textView = (TextView) convertView.findViewById(R.id.title);
textView.setText(mTitles[position]);
}
convertView.setTag(mTabTags[position]);
return convertView;
}