my text view not align on center below is my code this is my scren shot
i just want to align text view center of screen help me please
<RelativeLayout
android:id="#+id/lytTitlebar"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="#drawable/border"
android:layout_alignParentTop="true">
<ImageButton
android:id="#+id/imgNavBack"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/nav_back"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#color/text"
android:text="#string/category_list"
android:layout_toRightOf="#+id/imgNavBack"
android:layout_centerVertical="true"/>
<ImageButton
android:id="#+id/imgRefresh"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/refresh"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
Try this:
<TextView
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="#color/text"
android:text="#string/category_list"
android:gravity="center"
android:layout_toRightOf="#+id/imgNavBack"
android:layout_toLeftOf="#+id/imgRefresh"
android:layout_centerVertical="true"/>
Just copy layout and replace with your icon it will work.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff4444" >
<Button
android:id="#+id/header_toogel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher" />
<Button
android:id="#+id/header_search_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/ic_launcher" />
<TextView
android:id="#+id/sub_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Your Text Will Be Here"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
You should use both for textview
android:layout_centerVertical="true"
and
android:layout_centerHorizontical="true"
or
you can use
android:layout_centerInParent="true"
Related
Hi, I have two text view and one image view inside a relative layout,
I want to align image view centre according to textview parallel, but
now imagview aligning down parallel to text view, pls help me.i want result
as 1st image,but now am getting like second image
<LinearLayout
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:orientation="vertical">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_width="match_parent">
<TextView
android:id="#+id/totPendingTxt"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_width="wrap_content"
android:text="TOTAL"
android:textAllCaps="true"
android:textColor="#color/Color"
android:textSize="#dimen/text_size_small" />
<ImageView
android:contentDescription="#string/icon"
android:id="#+id/imgPendingOrder"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/totPendingTxt"
android:layout_width="wrap_content"
android:src="#drawable/icon_arrow" />
<TextView
android:id="#+id/totalPendingOrders"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:text=""
android:textAllCaps="true"
android:textColor="#color/Color"
android:textSize="#dimen/text_size_small" />
</RelativeLayout>
</LinearLayout>
Replace your code with my following code,may b it will help you:)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/totPendingTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:text="TOTAL"
android:textAllCaps="true"
android:textColor="#color/Color"
android:textSize="#dimen/text_size_small" />
<ImageView
android:id="#+id/imgPendingOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/icon_arrow" />
<TextView
android:id="#+id/totalPendingOrders"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text=""
android:textAllCaps="true" />
</RelativeLayout>
</LinearLayout>
I am using relative layout in my android app.
Following is my main.xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill"
tools:context="com.example.asdf.MainActivity" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:src="#drawable/bgg" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="22dp"
android:layout_marginTop="22dp"
android:gravity="center"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:text=" Factualnote is an web annotation application, which helps the users to mark the specific text, element, page, video, etc in a web page and share it to like-minded people.\r\n \r\nAs we know the relevant data has been wide-spreaded across various sites under many intentions, factualnote is a type of social software tool in which factual data are brought forward or narrow down to the web users."
android:textColor="#ffffff"
android:textSize="25sp"
android:textStyle="normal|italic" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<EditText
android:id="#+id/url"
android:layout_width="290dp"
android:layout_height="33dip"
android:layout_above="#+id/button_show"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:background="#ffffff"
android:ems="17"
android:hint="#string/edit_hint"
android:radius="10dp"
android:singleLine="true"
android:text="http://www.zeptoh.com/lynked/sel.html"
android:textColor="#000000"
android:textSize="16sp" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/blue_button"
android:text="#string/button_title"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/undo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="9"
android:background="#drawable/blue_button2"
android:text="#string/undo"
android:textColor="#ffffff" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="9"
android:background="#drawable/blue_button2"
android:text="Mark"
android:textColor="#ffffff" />
<Button
android:id="#+id/done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="10"
android:background="#drawable/blue_button2"
android:text="Generate"
android:textColor="#ffffff" />
<Button
android:id="#+id/redo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="9"
android:background="#drawable/blue_button2"
android:text="#string/redo"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:id="#+id/rl2"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<EditText
android:id="#+id/name"
android:layout_width="250dp"
android:layout_height="33dip"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#ffffff"
android:ems="17"
android:layout_gravity="center_horizontal"
android:hint="Enter Title"
android:singleLine="true"
android:textColor="#000000"
android:textSize="16sp" />
<EditText
android:id="#+id/desc"
android:layout_width="250dp"
android:layout_height="33dip"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:background="#ffffff"
android:ems="17"
android:layout_gravity="center_horizontal"
android:hint="Description about your note"
android:singleLine="true"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:id="#+id/privateText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/desc"
android:layout_below="#+id/desc"
android:layout_marginTop="10dp"
android:text="Private Note:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:textSize="20sp"
android:checked="true"
android:buttonTint="#color/desing_color"
android:textStyle="bold" />
<RadioGroup
android:id="#+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/privateText"
android:layout_toRightOf="#+id/privateText"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:text="Yes"
android:buttonTint="#color/desing_color"
android:textColor="#ffffff"
android:textSize="15sp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/privateText"
android:layout_marginLeft="14dp"
android:layout_toRightOf="#+id/yes"
android:text="No"
android:textColor="#ffffff"
android:textSize="15sp"
android:checked="true"
android:buttonTint="#color/desing_color"
android:textStyle="bold" />
</RadioGroup>
<Button
android:id="#+id/generate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="#drawable/blue_button"
android:layout_below="#+id/radioSex"
android:layout_marginTop="10dp"
android:layout_marginLeft="70dp"
android:textColor="#ffffff"
android:text="Generate Note" />
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_below="#+id/radioSex"
android:background="#drawable/blue_button"
android:layout_marginTop="10dp"
android:layout_marginLeft="200dp"
android:textColor="#ffffff"
android:text="Back" />
</RelativeLayout>
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
I put progress bar to center in horizontal and vertical. But that is placed on top of the screen only.
When I remove Linear layout rl2, progress bar appears center.
What I need to do to get progress bar in center even I have rl2.
Try adding
android:layout_centerInParenta="true"
to the progressbar and tell me if it works.
Did you try to remove android:gravity="fill" from the main container? (the first relative layout, the one that contains all the layout)
add the following line in your xml file,
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
if its not work, then first add progressbar and then add your views. Maybe it will work.
I have an issue trying align textView to the center of layout: when I try to do this - it has a conflict with a button on the left - if text is too long - it become hidden under the button. Text length can be very different and I need it in the center of layout but not under/on the button.
Here is the xml file of activity layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentRight="false" />
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginRight="5dp" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/item_content_scroll_view"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:id="#+id/item_content_image"
android:src="#drawable/ic_no_thumbnail"
android:maxHeight="125dp"
android:maxWidth="125dp"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_subtitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Subtitle"
android:layout_alignTop="#+id/item_content_image"
android:layout_toRightOf="#+id/item_content_image"
android:layout_toEndOf="#+id/item_content_image"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_pubdate"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Date"
android:layout_below="#+id/item_content_subtitle"
android:layout_alignLeft="#+id/item_content_subtitle"
android:layout_alignStart="#+id/item_content_subtitle"
android:textSize="10dp"
android:layout_marginTop="10dp" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="blabla"
android:layout_below="#+id/item_content_pubdate"
android:layout_alignStart="#+id/item_content_pubdate"
android:layout_alignParentStart="true"
android:layout_margin="10dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try using LinearLayout with layout-weight for this to avoid conflict. Change your first relativelayout to below one
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="7">
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="2"
android:background="#drawable/chemist" />
<TextView
android:id="#+id/item_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="5"
android:autoText="false"
android:gravity="center"
android:maxLines="2"
android:singleLine="true"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/Black"
android:textStyle="bold" />
</LinearLayout>
Change Your RelativeLayout to LinearLayout and use android:layout_weight attribute of layout to do this.
<LinearLayout
android:id="#+id/item_content_action_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1"
>
<ImageButton
android:id="#+id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="#drawable/chemist" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:gravity="center"
android:layout_weight="1"
android:autoText="false"/>
</LinearLayout>
Make the layout_gravity of the textview item_content_title as "center_horizontal".
And add android:layout_toLeftOf="#+id/item_content_title" under the ImageButton item_content_back_button.
Hope it was what you wanted.
Your Action bar layout has to be like this-
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/item_content_action_bar_layout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/colorBlue"
android:padding="10dp">
<ImageButton
android:layout_width="120dp"
android:layout_height="45dp"
android:id="#+id/item_content_back_button"
android:background="#drawable/back_button_selector"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dp" />
<TextView
android:toRightOf="#id/item_content_back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/item_content_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#color/colorWhite"
android:textAlignment="center"
android:singleLine="true"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:autoText="false"
android:layout_centerInParent="true" />
</RelativeLayout>
Hi I have a problem with centering TextView in ScrollView. I want to center my TextViews with ids hajs, textView01, textView02 vertically in order to be in the center of height of imageViews. It's strange because in the Android Studio design I see everything right, but when I try on device I get these TextViews in the top of the TextView.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal" >
<TextView
android:id="#+id/hajs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView1"
android:layout_centerInParent="true"
android:layout_toLeftOf="#+id/imageView1"
android:background="#41BF17"
android:gravity="center_vertical|center|center_horizontal"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textSize="70sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#41BF17"
android:gravity="center"
android:text="#string/zaoszczedziles"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView2"
android:adjustViewBounds="true"
android:background="#41BF17"
android:maxWidth="100dp"
android:src="#drawable/moneybag" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/hajs"
android:background="#41BF17"
android:gravity="center"
android:text="#string/dni_bez_papierosow"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textStyle="bold" />
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView3"
android:adjustViewBounds="true"
android:background="#41BF17"
android:maxWidth="100dp"
android:src="#drawable/calendar" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/ImageView01"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/hajs"
android:layout_alignTop="#+id/ImageView01"
android:layout_centerInParent="true"
android:background="#41BF17"
android:gravity="center"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFF"
android:textSize="70sp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I do have a UI, and some elements in this user interface. I want the elements always in the center vertically. The problem is that, when i set layout_centerInParent it becomes centered but overrides the bottom elements. I don't want it. Here is how it looks like at this moment:
And the xml file is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="#dimen/top_mr_image"
android:src="#drawable/temp" />
<LinearLayout
android:id="#+id/r1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:background="#drawable/r1bg"
android:layout_marginRight="35dp"
android:layout_marginBottom="10dp"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Start"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="#dimen/txt_r4_size" />
</LinearLayout>
<LinearLayout
android:id="#+id/r2"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_below="#+id/r1"
android:background="#drawable/r2bg"
android:layout_marginRight="25dp"
android:layout_marginBottom="10dp"
>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="HOW TO"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="#dimen/txt_r4_size" />
</LinearLayout>
<LinearLayout
android:id="#+id/r3"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_below="#+id/r2"
android:background="#drawable/r3bg"
android:layout_marginRight="15dp"
android:layout_marginBottom="10dp"
>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Support"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="#dimen/txt_r4_size" />
</LinearLayout>
<RelativeLayout
android:layout_marginTop="20dp"
android:id="#+id/r4"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/r4bg"
android:clickable="true"
android:onClick="onClick" >
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="You have:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="#dimen/txt_r4_size" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/textView11"
android:layout_marginLeft="20dp"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="30dp" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/textView12"
android:layout_marginLeft="20dp"
android:text="CCCCCC"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="#dimen/txt_r4_size" />
</RelativeLayout>
I want it to be always in the center vertically and not to override some of top and bottom elements. How to achieve this? I don't want to hardcode it for different screen resolutions.
if you do not want the bottom items being overlapped, then you need to make them relative to the tallest view vertically centered. Set Align Below so they would not overlap.