Imagebuttons won't align on the right next to eachother - android

I'm dynamically injecting rows in a container of a fragment.
But I just can't seem to get the three image buttons aligned to the right, next to each other.
Anyone an idea?
Fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scenesScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/switchLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/scenesTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/switch_title"
android:text="#string/title_switches" />
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="vertical">
</LinearLayout>
<TextView
android:id="#+id/statusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</LinearLayout>
</ScrollView>
My row layout:
<?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="wrap_content"
android:paddingBottom="10dp">
<TextView
android:id="#+id/switch_name"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/switch_row_name"
android:text="Switch name"/>
<TextView
android:id="#+id/switch_lastSeen"
android:layout_below="#id/switch_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/switch_row_lastSeen"
android:text="#string/last_seen"/>
<TextView
android:id="#+id/switch_status"
android:layout_below="#id/switch_lastSeen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/switch_row_level"
android:text="#string/status"/>
<ImageButton
android:id="#+id/switch_button_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_up"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<ImageButton
android:id="#+id/switch_button_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_stop"
android:layout_toLeftOf="#+id/switch_button_down"
android:layout_toStartOf="#+id/switch_button_down"
android:layout_centerVertical="true" />
<ImageButton
android:id="#+id/switch_button_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_down"
android:layout_toLeftOf="#+id/switch_button_up"
android:layout_toStartOf="#+id/switch_button_up"
android:layout_centerVertical="true" />
</RelativeLayout>
How the row looks on my phone (the same on a API 19 AVD):
How Android Studio, when designing, shows the row:

try this
<?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="wrap_content"
android:paddingBottom="10dp">
<TextView
android:id="#+id/switch_name"
style="#style/switch_row_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="Switch name" />
<TextView
android:id="#+id/switch_lastSeen"
style="#style/switch_row_lastSeen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/switch_name"
android:text="#string/last_seen" />
<TextView
android:id="#+id/switch_status"
style="#style/switch_row_level"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/switch_lastSeen"
android:text="#string/status" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:orientation="horizontal">
<ImageButton
android:id="#+id/switch_button_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_up" />
<ImageButton
android:id="#+id/switch_button_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_stop" />
<ImageButton
android:id="#+id/switch_button_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_arrow_down" />
</LinearLayout>
</RelativeLayout>

Related

Relative layout views not shrinking down on smaller screen

I have an activity that hosts a fragment and a Button, the fragment should take the majority of the screen while the button should take a small part of the lower part of the screen.
However I can't make the Relative layout shrink down so that the button doesn't overlap over the fragment.
below is my activity layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_registration"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.example.activities.RegistrationActivity">
<fragment
android:name="com.example.fragments.registration.GenderFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:layout="#layout/fragment_gender" />
<Button
android:id="#+id/profile_progress_bar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/colorPrimary"
android:text="BUTTON TEXT"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
and below is the layout of the fragment
<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="wrap_content"
tools:context="com.example.fragments.registration.GenderFragment">
<ImageView
android:id="#+id/welcome_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingTop="#dimen/xlarge_top_margin"
android:src="#drawable/bienvenido" />
<TextView
android:id="#+id/gender_explanation"
style="#style/HeaderTitleWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/welcome_note"
android:layout_centerHorizontal="true"
android:text="WELCOME TO THE APP"
android:textSize="#dimen/header_title_text_view_xtra_big_size" />
<LinearLayout
android:id="#+id/gender_avatar_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gender_explanation"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/medium_top_margin"
android:orientation="vertical">
<ImageView
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/woman"
android:scaleType="centerInside" />
<ImageView
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/man"
android:scaleType="centerInside" />
</LinearLayout>
<Button
android:id="#+id/next"
style="#style/AppButtonMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/gender_explanation"
android:layout_alignLeft="#+id/gender_explanation"
android:layout_alignRight="#+id/gender_explanation"
android:layout_alignStart="#+id/gender_explanation"
android:layout_below="#+id/gender_avatar_holder"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/large_top_margin"
android:text="NEXT"
android:textStyle="normal|bold" />
</RelativeLayout>
below is a screenshot of how it looks
Your frangment content is too big, so you should user ScrollView inside your layout, like this.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.example.fragments.registration.GenderFragment">
<ImageView
android:id="#+id/welcome_note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingTop="#dimen/xlarge_top_margin"
android:src="#drawable/bienvenido" />
<TextView
android:id="#+id/gender_explanation"
style="#style/HeaderTitleWhite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/welcome_note"
android:layout_centerHorizontal="true"
android:text="WELCOME TO THE APP"
android:textSize="#dimen/header_title_text_view_xtra_big_size" />
<LinearLayout
android:id="#+id/gender_avatar_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gender_explanation"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/medium_top_margin"
android:orientation="vertical">
<ImageView
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/woman" />
<ImageView
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/man" />
</LinearLayout>
<Button
android:id="#+id/next"
style="#style/AppButtonMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/gender_explanation"
android:layout_alignLeft="#+id/gender_explanation"
android:layout_alignRight="#+id/gender_explanation"
android:layout_alignStart="#+id/gender_explanation"
android:layout_below="#+id/gender_avatar_holder"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/large_top_margin"
android:text="NEXT"
android:textStyle="normal|bold" />
</RelativeLayout>

Unable create layout with image and text for listvieitem

<?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="90dip"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<TextView
android:id="#+id/rowcontact_txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:text="Usama Sadiq"
android:textColor="#3a3838"
android:textSize="15dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/rowcontact_imgLocationIcon"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_below="#+id/rowcontact_txtName"
android:layout_marginLeft="10dip" />
<TextView
android:id="#+id/rowcontact_txtLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rowcontact_txtName"
android:layout_toRightOf="#+id/rowcontact_imgLocationIcon"
android:text="Dubai"
android:textColor="#898788"
android:textSize="11.5dp" />
<ImageView
android:id="#+id/rowcontact_imgIcon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignBottom="#+id/rowcontact_txtLocation"
android:layout_marginLeft="94dp"
android:layout_toRightOf="#+id/rowcontact_txtName" />
</RelativeLayout>
</RelativeLayout>
i am trying to create layout for list-view item but i am not able to fix position of image and text with three different Position please tell me solution how to fix it. i have to create listviow item i am able to display list-view but like given screen
i have all icon an all but am unable to fix potion of text-view and image view like given screen
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="2"
android:layout_margin="5dp"
>
<TextView
android:id="#+id/rowcontact_txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Usama Sadiq"
android:textColor="#3a3838"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/rowcontact_txtLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rowcontact_txtName"
android:layout_toRightOf="#+id/rowcontact_imgLocationIcon"
android:text="Dubai"
android:textColor="#898788"
android:textSize="11.5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

RelativeLayout for ListView item

First of all, if this question is a copy, I am sorry!!!
I have this layout for a ListView item and it doesn't work ok.
I want a center line separator, On the left of the line one number and another one on the right.
<?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"
android:padding="10dp">
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text=" - " />
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/separador"
android:layout_centerVertical="true"
android:text="188"/>
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/separador"
android:layout_centerVertical="true"
android:text="200"/>
</RelativeLayout>
If I change this line:
<?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"
android:padding="10dp">
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text=" - " />
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/separador"
android:layout_centerVertical="true"
android:text="188"/>
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="200"/>
</RelativeLayout>
I have this result:
image
Why??
Thanks!!!
I really want this: image
I get this with this code:
<?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"
android:padding="10dp">
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:paddingRight="50dp"
android:textStyle="bold"
android:textSize="20sp"
android:text="100"/>
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:paddingLeft="50dp"
android:textStyle="bold"
android:textSize="20sp"
android:text="200"/>
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignBottom="#id/local_ptos"
android:text=" - " />
<TextView
android:id="#+id/local_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignBottom="#id/local_ptos"/>
<TextView
android:id="#+id/visitante_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="#id/visitante_ptos"/>
</RelativeLayout>
But I don't like this code and I want the separator line vertical centered with numbers.
Sorry my English
You needed following attributes: android:layout_toLeftOf and android:layout_toRightOf.
<?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"
android:padding="10dp" >
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text=" - " />
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/separador"
android:layout_centerVertical="true"
android:text="188" />
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/separador"
android:text="200" />
</RelativeLayout>
Hope i have understood your question here is your xml code:
<?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"
android:padding="10dp" >
<TextView
android:id="#+id/separador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text=" - " />
<TextView
android:id="#+id/local_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/separador"
android:layout_centerVertical="true"
android:text="188" />
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/separador"
android:layout_centerVertical="true"
android:text="200" />
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textStyle="bold"
android:text="JPS" />
<TextView
android:id="#+id/visitante_ptos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:textStyle="bold"
android:text="CABA" />
</RelativeLayout>

why is my relativeLayout doesn't appear below its sibling linearLayout?

I have the following xml
<?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="wrap_content"
android:background="#color/blue_bg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical" >
<com.my.view.text.MyTextView
android:id="#+id/whyResgisterHeaderText"
style="#style/textOnBg"
android:layout_marginTop="25dp"
android:text="WHY REGISTER?"
android:textStyle="bold" />
<com.my.view.text.MyTextView
android:id="#+id/whyResgisterBodyText"
style="#style/textOnBg"
android:text="Help us keep your account safe"
android:textStyle="normal" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp"
android:src="#drawable/signup_illu_why" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="#+id/gotItButton"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:background="#drawable/btn_selector"
android:padding="0dp" />
<com.my.view.text.MyTextView
android:id="#+id/gotItText"
style="#style/textOnBg"
android:layout_marginTop="25dp"
android:text="Got it"
android:textColor="#00bcfe"
android:textSize="16dp"
android:textStyle="italic" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#70a5b3" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.my.view.text.MyTextView
style="#style/textOnBg"
android:layout_toLeftOf="#+id/skipIcon"
android:text="Skip"
android:textStyle="normal" />
<ImageView
android:id="#id/skipIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/signup_skip_icon" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
I want my screen to look like:
but it looks like:
1) why cannot I see the fotter relativeLayout (with the "skip")
2) how can I center the gotItText textView? why isn't it center with current properties?
Because your root layout is a RelativeLayout.
You should declare an ID for the first LinearLayout, and then use layout_below property on the second one. Remember, their positions are relatives so if you don't specify the location of the second Linear, it will be paint over the first one.
If you want to get one linear below the other automatically use a LinearLayout as main root.
Edited you code, replaced the custom EditTexts, and removed the styles, set new heights to the layout and it seems to be working as you want.
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/whyResgisterHeaderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="WHY REGISTER?"
android:textStyle="bold" />
<TextView
android:id="#+id/whyResgisterBodyText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Help us keep your account safe"
android:textStyle="normal" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="#+id/gotItButton"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:padding="0dp" />
<TextView
android:id="#+id/gotItText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:text="Got it"
android:textColor="#00bcfe"
android:textSize="16dp"
android:textStyle="italic" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#70a5b3" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/skipIcon"
android:text="Skip"
android:textStyle="normal" />
<ImageView
android:id="#id/skipIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>

How to align a set of views(button, image) horizontally center

Here xml code i tried
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/home_icon"
/>
<Button
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="OnHomeSelected"
/>
</LinearLayout>
<ImageView
android:id="#+id/ivnetconstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ledred"
android:layout_gravity="right"
/>
</LinearLayout>
output generated using above xml file
I want to align home image & home button to center and red circle image to right of the layout.
thanks in advance
Try this:
<?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"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:gravity="center"
>
<ImageView
android:id="#+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/home_icon"
/>
<Button
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image1"
android:onClick="OnHomeSelected"
/>
</RelativeLayout>
<ImageView
android:id="#+id/ivnetconstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ledred"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Change your layout like this..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/ivnetconstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/home_icon" />
<Button
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:onClick="OnHomeSelected" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/btnHome"
android:gravity="center"
android:src="#drawable/ledred" />
</RelativeLayout>
use Relative Layout which provide you mutiple properties to align views.
shot try with below code.
<?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"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon" />
<Button
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="OnHomeSelected" />
</LinearLayout>
<ImageView
android:id="#+id/ivnetconstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>

Categories

Resources