I am trying to create a List Activities Item Layout as follows
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:contentDescription="ss" android:id="@+id/place_category_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="15dp" android:paddingTop="10dp" android:src="@drawable/marker"/> <TextView android:id="@+id/place_distance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="320" /> <TextView android:id="@+id/place_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/place_category_icon" android:text="Place Name" android:textColor="#FFFF00" android:textSize="14sp" android:textStyle="bold" /> </RelativeLayout>
I want the Layout to be displayed as follows.
i want to align it center Horizontal
If you want to make it center then use android:layout_centerVertical="true" in the TextView. my Relative Layout has fill_parent for both height and width. Since this is the layout for an Item inside a ListView i want many of them to stack on top of each other.
If you have a single Button in your Activity and you want to center it the simplest way is to use a RelativeLayout and set the android:layout_centerInParent=”true” property on the Button.
android:layout_centerHorizontal="true" android:gravity="center" I think it's correct. so that TextView will be centered in Layout, and text will be centered in TextView.
I hope this will work
EDITED
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingRight="15dp" > <ImageView android:id="@+id/place_category_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:contentDescription="ss" android:paddingTop="10dp" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/place_distance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:text="320" /> <TextView android:id="@+id/place_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/place_category_icon" android:text="Place Name" android:textColor="#FFFF00" android:textSize="14sp" android:textStyle="bold" /> </RelativeLayout>
If you want to make it center then use android:layout_centerVertical="true"
in the TextView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With