Center in Parent overrides the bottom elements - android

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.

Related

Progress bar is not center when under relative layout

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.

Center gravity in ScrollView

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 need to scroll my Scroll view behind the relative layout( like overlay)

>
This is my XML code, here i have coded the relative layout with a image which contains shadow in it and scroll view containing some other stuffs. I have to make my scroll view to scroll under the relative layout to get shadow effects."***
![have a look into the image at the bottom][1]
![
<?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:background="#drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#drawable/bar_doubleline"
android:paddingTop="10dp" >
<Button
android:id="#+id/backtomemberdetailbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#f7931d"
android:text="Back"
android:textColor="#ffffff"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="#+id/membercardjoinbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#f7931d"
android:text="Join"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/membercardtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Member Card"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-3dp"
android:fadingEdge="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="#drawable/card1" />
</TableRow>
<TextView
android:id="#+id/vmembercardtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:text=" Member card"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="#+id/infotext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:text="Company info"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="#+id/descriptiontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:text="Description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
android:textSize="22sp"
android:textStyle="bold" />
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:gravity="center" >
<Button
android:id="#+id/memberdetailbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/start2"
android:text="view event"
android:textColor="#FFFF"
android:textSize="22dp"
android:textStyle="bold" />
</TableRow>
</LinearLayout>
</ScrollView>
</LinearLayout>][1]
[1]: http://i.stack.imgur.com/tmY8y.jpg
[1]: http://i.stack.imgur.com/pXCzx.jpg
you can override the touch event for scroll and return false. Thus the event will not be consumed and will be passed to the view below it i.e scrollView in your case. And it will work as it should even below your overlay layout.
This link will help You:
How to transfer touch events to the view beneath in a RelativeLayout?

Linear and Relative Layout aligment

I am unable to get the below shown layout..can anyone let me know how to achieve this layout ?
This is what I have but unable to get the specified layout.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left"
android:layout_weight="1">
<ImageView
android:id="#+id/someimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#88FF0000" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right">
<TextView
android:id="#+id/txtview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtview2"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="right"
android:layout_below="#id/txtview1"/>
<TextView
android:id="#+id/txtview3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:textColor="#003399"
android:textSize="19sp"
android:textStyle="bold"
android:layout_below="#id/txtview2"/>
</RelativeLayout>
</LinearLayout>
I want to get this as final layout:
You can use a single RelativeLayout
You can remove the unwanted RelativeLayout with black background. (Just to differentiate i added another relative layout with black background)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="15dp"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:layout_below="#+id/imageView1" >
</RelativeLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="16dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="54dp"
android:layout_marginTop="14dp"
android:text="TextView" />
</RelativeLayout>
Edit:
You can also center the text in TextView and use match_parent for the layout width and remove the unwanted realtive layout. Notice the change android:layout_toRightOf="#+id/imageView1" in the below code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView2"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="15dp"
android:text="TextView" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView3"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="15dp"
android:text="TextView" />
<TextView
android:id="#+id/textView1"
android:layout_toRightOf="#+id/imageView1"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:text="TextView" />
</RelativeLayout>
snap
You need to set the layout_width of all TextViews to fill_parent.
Note that your code should not even compile because the layout_width attribute is mandatory, and you don't specify it for the second TextView, and it also does not have a style attribute where it might be specified.
The below hierarchy can also do what you want:
Linear-Horizontal
Linear-Vertical
imageview
Linear-Horizontal
textview
textview
textview
What about a vertical linear layout where you put the image view in. Also put a horizontal linear layout in, where you place the textviews. Set the vertical height to wrap content and the horizontal to match parent.
Let me know if this works for you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="left"
android:layout_weight="1">
<ImageView
android:id="#+id/someimage"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#88FF0000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<TextView
android:id="#+id/txtview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="TextView1"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtview1"
android:focusable="false"
android:gravity="center"
android:text="TextView2" />
<TextView
android:id="#+id/txtview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="19sp"
android:textStyle="bold"
android:gravity="center"
android:text="Textview 3"
android:layout_below="#id/txtview2"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

Center Button horizontally doesn't work

hy!
I want to center my button horizontally, but this never work.
My Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/minage"
android:layout_alignParentLeft="true"
android:padding="5dp" />
<TextView
android:id="#+id/ml_minage_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp"/>
</RelativeLayout>
<SeekBar
android:id="#+id/ml_minage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:max="100"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/maxage"
android:padding="5dp"/>
<TextView
android:id="#+id/ml_maxage_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/ml_maxage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/distance"
android:padding="5dp" />
<TextView
android:id="#+id/ml_distance_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="5dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/ml_distance"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#style/NFFSeek"
android:progressDrawable="#drawable/myseekbar"
android:layout_margin="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gender"
android:padding="5dp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="#drawable/rbon" >
<RadioButton
android:id="#+id/ml_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:button="#drawable/rbselector"
android:checked="true"
android:drawablePadding="10dp"
android:text="#string/rb_female"
android:textColor="#000000"
android:paddingLeft="42dp" />
<RadioButton
android:id="#+id/ml_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rb_male"
android:button="#drawable/rbselector"
android:layout_margin="5dp"
android:textColor="#000000"
android:paddingLeft="42dp"
/>
</RadioGroup>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/ml_stbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#drawable/custom_button"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:padding="10dp"
android:text="Flirt"
android:textColor="#ffffff"
android:textSize="12pt"
android:typeface="serif" />
</RelativeLayout>
</LinearLayout>
this xml doesn't fit the button in the middle please help.
The problem is that the RelativeLayout does not span the width of the page, it's width is wrap_content. The button is centered in the RelativeLayout, but that layout is only as wide as the button, and is mashed up against the left side of the screen.
Make the inner RelativeLayout's width as match_parent.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/ml_stbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#drawable/custom_button"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="10dp"
android:text="Flirt"
android:textColor="#ffffff"
android:textSize="12pt"
android:typeface="serif" />
</RelativeLayout>
This isn't speaking directly to your question, but your view hierarchy is too complicated. I suggest you replace all of the LinearLayout and RelativeLayout elements with a single RelativeLayout that spans the whole thing.

Categories

Resources