Android xml layout about CheckBox and RadioButton - android

There have two RadioButton, Twelve Checkbox and one send button,each button has a custom selector.
RadioButton and Checkbox out of range, can not let all RadioButton and Checkbox in the android xml layout.
I used ScrollView, but it have some error about "Exception raised during rendering: ScrollView can host only one direct child".
I don't know how can RadioButton and Checkbox in there range.
How to change RadioButton and CheckBox in to the RadioButton in there range?
thanks.
<?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" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/etIdUserName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdUseracc2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdPassre2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者性別"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<RadioButton
android:id="#+id/boy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="#+id/girl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者年齡"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/under"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="18以下"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23~27"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="18~23"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="28~32"
android:textSize="15sp" />
<CheckBox
android:id="#+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="32以上"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者興趣"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/girluse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="女裝與服飾配件、女包精品與女鞋"
android:textSize="15sp" />
<CheckBox
android:id="#+id/makeup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="美容保養與彩妝"
android:textSize="15sp" />
<CheckBox
android:id="#+id/boyuse"
android:layout_width="152dp"
android:layout_height="wrap_content"
android:text="男性精品與服飾"
android:textSize="15sp" />
<CheckBox
android:id="#+id/electronicproduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="電腦、平板與周邊"
android:textSize="15sp" />
<CheckBox
android:id="#+id/cellphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手機、配件與通"
android:textSize="15sp" />
<CheckBox
android:id="#+id/food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美食與地方特產"
android:textSize="15sp" />
<CheckBox
android:id="#+id/Stationery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文具與事務用"
android:textSize="15sp" />
<Button
android:id="#+id/setbutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="送出"
android:textSize="15sp" />
</ScrollView>
</LinearLayout>

"ScrollView can host only one direct child".
So simply wrap everything in a LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/etIdUserName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdUseracc2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdPassre2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者性別"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<RadioButton
android:id="#+id/boy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="#+id/girl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者年齡"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/under"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="18以下"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23~27"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="18~23"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="28~32"
android:textSize="15sp" />
<CheckBox
android:id="#+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="32以上"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者興趣"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/girluse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="女裝與服飾配件、女包精品與女鞋"
android:textSize="15sp" />
<CheckBox
android:id="#+id/makeup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="美容保養與彩妝"
android:textSize="15sp" />
<CheckBox
android:id="#+id/boyuse"
android:layout_width="152dp"
android:layout_height="wrap_content"
android:text="男性精品與服飾"
android:textSize="15sp" />
<CheckBox
android:id="#+id/electronicproduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="電腦、平板與周邊"
android:textSize="15sp" />
<CheckBox
android:id="#+id/cellphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手機、配件與通"
android:textSize="15sp" />
<CheckBox
android:id="#+id/food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美食與地方特產"
android:textSize="15sp" />
<CheckBox
android:id="#+id/Stationery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文具與事務用"
android:textSize="15sp" />
<Button
android:id="#+id/setbutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="送出"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>

As per the Logcat says Exception raised during rendering: ScrollView can host only one direct child. One can have only one direct child view to ScrollView. As you have so many check boxes and RadioButton inside ScrollView it throws an error.
You just need to add all your Checkbox and RadioButton inside View with ParentView as ScrollView which can handle all your RadioButton and Checkboxes. In here I've added Linearlayout as ParentView for all your Checkboxes and RadioButton.
Explaination:
ScrollView // ParentView
LinearLayout // DirectChild of ScrollView
RadioButton & Checkboxes // Direct child of LinearLayout
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" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/etIdUserName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdUseracc2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:id="#+id/etIdPassre2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="10sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者性別"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<RadioButton
android:id="#+id/boy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="#+id/girl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者年齡"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/under"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="18以下"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23~27"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="18~23"
android:textSize="15sp" />
<CheckBox
android:id="#+id/between3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="28~32"
android:textSize="15sp" />
<CheckBox
android:id="#+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="32以上"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用者興趣"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<CheckBox
android:id="#+id/girluse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="女裝與服飾配件、女包精品與女鞋"
android:textSize="15sp" />
<CheckBox
android:id="#+id/makeup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="美容保養與彩妝"
android:textSize="15sp" />
<CheckBox
android:id="#+id/boyuse"
android:layout_width="152dp"
android:layout_height="wrap_content"
android:text="男性精品與服飾"
android:textSize="15sp" />
<CheckBox
android:id="#+id/electronicproduct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="電腦、平板與周邊"
android:textSize="15sp" />
<CheckBox
android:id="#+id/cellphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="手機、配件與通"
android:textSize="15sp" />
<CheckBox
android:id="#+id/food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="美食與地方特產"
android:textSize="15sp" />
<CheckBox
android:id="#+id/Stationery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文具與事務用"
android:textSize="15sp" />
<Button
android:id="#+id/setbutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="送出"
android:textSize="15sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>

Related

Listview can't displayed the last item

This is the my current listivew:
My problem is i can't display my last item in the list. It's like getting cut by my phone.
Here is the xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="280dp"
android:background="#drawable/dfcomment3"
android:layout_weight="0.07">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Add comment"
android:id="#+id/button12"
android:layout_marginTop="215dp"
android:layout_marginLeft="5dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update Post"
android:id="#+id/button13"
android:layout_marginTop="215dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Close This"
android:id="#+id/button14"
android:layout_marginTop="215dp" />
</LinearLayout>
<TextView
android:layout_marginLeft="10dp"
android:textSize="35dp"
android:id="#+id/textView11"
android:gravity="center"
android:text="ID"
android:textStyle="bold"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView12"
android:text="Name"
android:textSize="16dp"
android:textColor="#994495"
android:layout_marginTop="190dp"
android:layout_marginLeft="210dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView13"
android:text="Lastname"
android:textStyle="bold"
android:textSize="16dp"
android:layout_marginLeft="90dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/id"
android:layout_toEndOf="#+id/id"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView14"
android:text="title"
android:textSize="15dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260dp"
android:layout_below="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_marginTop="190dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="descr"
android:textSize="21dp"
android:textColor="#994495"
android:id="#+id/textView15"
android:layout_marginLeft="110dp"
android:layout_marginTop="60dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dept"
android:textStyle="italic"
android:textColor="#994495"
android:id="#+id/textView16"
android:layout_marginLeft="180dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags"
android:textStyle="italic"
android:textSize="14dp"
android:textColor="#994495"
android:id="#+id/textView17"
android:layout_marginLeft="120dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="#70CC86"
android:id="#+id/textView18"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textColor="#994495"
android:id="#+id/textView19"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
As much as possible i want to stick with the listview because i'm not familiar with the recyclerview. if theres any way to fix this, i would be glad.
Check the image for the reference of my problem.
There's actually 4 items in the list and i can only view 2 items.
Firstly there is problem with your XML as when you use weightsum and layout_weight then you need not give dimensions in height or width.
This must be your XML.
Also I checked your XML there is some problem in you XML attributes too. Like you used "android:layout_below="#+id/id"" but in your xml there is no "id"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#drawable/dfcomment3"
android:layout_weight="70">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Add comment"
android:id="#+id/button12"
android:layout_marginTop="215dp"
android:layout_marginLeft="5dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Update Post"
android:id="#+id/button13"
android:layout_marginTop="215dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Close This"
android:id="#+id/button14"
android:layout_marginTop="215dp" />
</LinearLayout>
<TextView
android:layout_marginLeft="10dp"
android:textSize="35dp"
android:id="#+id/textView11"
android:gravity="center"
android:text="ID"
android:textStyle="bold"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView12"
android:text="Name"
android:textSize="16dp"
android:textColor="#994495"
android:layout_marginTop="190dp"
android:layout_marginLeft="210dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView13"
android:text="Lastname"
android:textStyle="bold"
android:textSize="16dp"
android:layout_marginLeft="90dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/id"
android:layout_toEndOf="#+id/id"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/textView14"
android:text="title"
android:textSize="15dp"
android:textColor="#994495"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="260dp"
android:layout_below="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_marginTop="190dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="descr"
android:textSize="21dp"
android:textColor="#994495"
android:id="#+id/textView15"
android:layout_marginLeft="110dp"
android:layout_marginTop="60dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dept"
android:textStyle="italic"
android:textColor="#994495"
android:id="#+id/textView16"
android:layout_marginLeft="180dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tags"
android:textStyle="italic"
android:textSize="14dp"
android:textColor="#994495"
android:id="#+id/textView17"
android:layout_marginLeft="120dp"
android:layout_marginTop="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="#70CC86"
android:id="#+id/textView18"
android:layout_marginLeft="290dp"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="date"
android:textColor="#994495"
android:id="#+id/textView19"
android:layout_marginLeft="10dp"
android:layout_marginTop="190dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="30"
android:layout_height="0dp" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
Add your java code if you are not getting 4 values into your ListView
Change you xml to :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<RelativeLayout
android:orientation="vertical"
android:id="#+id/border"
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_weight="0.07"--> Delete this
>
....
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="1" -> Add this
android:layout_height="0dp" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>

How to set RelativeLayout parent right side

Hi I am very new for android and here I have created two RelativeLayout on LinearLayout
My requirement is I want to set second Relative Layout at parent right side
According to my code screen seems to be like my below image
So how can I set second RelativeLayout at parent right side
code:
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ItemCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="GG00929-023"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="176000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:background="#android:color/holo_red_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On Hand"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reserve"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.68"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cut Qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
Try this Layout. I have applied some changes to your Layout. I have remove child Linear Layout because it is useless or android:layout_alignParentRight="true" will not get affected. Also added Relative Layout as your Root 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="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/RL1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ItemCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="GG00929-023"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="176000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#android:color/holo_red_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On Hand"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reserve"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.68"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cut Qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Linear Layout has no such attribute to set Right:
So you have to add the view with weight which will coverup the middle blank space.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ItemCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="GG00929-023"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="176000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:background="#android:color/holo_red_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On Hand"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reserve"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.68"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cut Qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Between the two RelativeLayout, insert a third View:
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
Because of it's layout weight, this will "push" your second RelativeLayout to the right side.
In order to use android:layout_alignParentRight="true", the parent should be RelativeLayout. The parent of your RelativeLayout is LinearLayout and if I'm not mistaken, you want that RelativeLayout to be at the right of parent. Either make the parent RelativeLayout, or give weight_sum to LinearLayout and weight to the children.
Try it in second RelativeLayout
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="0dp"
android:background="#android:color/holo_red_light">
android:layout_alignParentRight attribute only work in children of RelativeLayout. Now, you are using it in a child of a LinearLayout so it will not work.
You have few ways to do what you require. Ill give you 2.
First you can change the "Parent Layout" to Relative and add alignParentRight="true" and alignParentLeft="true" for the two LinearLayout.
Second, with the way you did it, you can change to width of the two LinearLayout to 0dp and then, add them layout_weight="1".
Try this code ::
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:padding="5dp">
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ItemCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="GG00929-023"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="176000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:background="#android:color/holo_red_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On Hand"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reserve"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.68"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cut Qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

How to center two sibling TextView in RelativeLayout?

I have layout like below. Need that b and c will be centered below a. To simplify view need only this one RelativeLayout if is possible.
<RelativeLayout
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="60dp">
<TextView
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test 1"
android:paddingTop="3dp" />
<TextView
android:id="#+id/b"
android:layout_below="#id/a"
android:paddingRight="5dp"
android:textColor="#000"
android:text="test 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/c"
android:layout_toRightOf="#id/b"
android:layout_below="#id/a"
android:textColor="#f00"
android:text="test 3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
UPDATE
Now i ended with something like below, but it is not the best, because b and c are not exactly below a.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="60dp">
<TextView
android:id="#+id/a"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test 1"
android:paddingTop="3dp" />
<TextView
android:layout_alignParentBottom="true"
android:paddingRight="5dp"
android:textColor="#000"
android:text="test 2"
android:id="#+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/b"
android:textColor="#f00"
android:id="#+id/c"
android:text="test 3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
you have to wrap them in another layout, like this:
<RelativeLayout
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="60dp">
<TextView
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test 1"
android:paddingTop="3dp" />
<LinearLayout
layout_centerHorizontal="true"
android:layout_below="#id/a"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/b"
android:paddingRight="5dp"
android:textColor="#000"
android:text="test 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/c"
android:textColor="#f00"
android:text="test 3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
Try this:
`<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp">
<TextView
android:id="#+id/a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test 1"
android:gravity="center_horizontal"
android:textColor="#000"
android:paddingTop="3dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_below="#id/a">
<TextView
android:paddingRight="5dp"
android:textColor="#000"
android:text="test 2"
android:id="#+id/b"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_toRightOf="#id/b"
android:layout_below="#id/a"
android:textColor="#f00"
android:id="#+id/c"
android:text="test 3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>`
Like this
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#dd80aa"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="This is on the top"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Maybe I will try to make this a long text"
android:id="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:layout_marginRight="88dp"
android:padding="20dp"
android:background="#aa80ee"
android:layout_marginEnd="88dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="This time I'll try to do this on the right side"
android:padding="20dp" android:background="#70aa80"
android:id="#+id/textView3"
android:layout_below="#+id/textView"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView"
android:layout_marginLeft="88dp"
android:layout_marginStart="88dp"/>
</RelativeLayout>
for situations like this I use View. This works perfect for me
<RelativeLayout
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="60dp">
<TextView
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test 1"
android:layout_centerHorizontal="true"
android:paddingTop="3dp" />
<View
android:id="#+id/center_view"
android:layout_width="0dip"
android:layout_height="0dip"
android:layout_centerHorizontal="true"
android:layout_below="#+id/a"/>
<TextView
android:id="#+id/b"
android:layout_below="#id/a"
android:layout_toLeftOf="#+id/center_view"
android:paddingRight="5dp"
android:textColor="#000"
android:text="test 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/c"
android:layout_toRightOf="#+id/center_view"
android:layout_below="#id/a"
android:textColor="#f00"
android:text="test 3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
That is not possible you need to use two viewgroup layout either you have to use linearlayout inside Relativelatyou or RelativeLayout inside RelativeLayout
You can only do like this if you use only one ReltiveLayout
Textview a is not in center of the relativelayout. Add android:layout_centerHorizontal="true" for textview a.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="60dp">
<TextView
android:id="#+id/a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="test 1"
android:paddingTop="3dp" />
<TextView
android:id="#+id/b"
android:layout_below="#id/a"
android:paddingRight="5dp"
android:textColor="#000"
android:text="test 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/c"
android:layout_toRightOf="#id/b"
android:layout_below="#id/a"
android:textColor="#f00"
android:text="test 3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
**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="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<TextView
android:id="#+id/txtView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="TextView1" />
<TextView
android:id="#+id/txtView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtView1"
android:layout_centerInParent="true"
android:text="TextView2" />
<TextView
android:id="#+id/txtView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txtView1"
android:layout_toRightOf="#+id/txtView2"
android:text="TextView3" />
</RelativeLayout>
</RelativeLayout>

TextView's of a Layout are overlapping

I've a problem with a layout, I'm really stuck and I can't found the solution...
I've this layout:
<RelativeLayout
android:layout_below="#+id/header_separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
>
<TextView
android:id="#+id/lbTitulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="10sp"
android:textSize="18sp"
android:text="#string/detalles_label_titulo"
android:width="60dp" />
<TextView
android:id="#+id/txtTitulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/lbTitulo"
android:layout_toRightOf="#id/lbTitulo"
android:text="#string/lorem_ipsum"
android:textSize="18sp" />
<TextView
android:id="#+id/lbFecha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtTitulo"
android:layout_alignLeft="#id/lbTitulo"
android:layout_marginTop="10sp"
android:textSize="18sp"
android:text="#string/detalles_label_fecha"
android:width="60dp" />
<TextView
android:id="#+id/txtFecha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/lbFecha"
android:layout_toRightOf="#id/lbFecha"
android:text="#string/lorem_ipsum"
android:textSize="18sp" />
<TextView
android:id="#+id/lbDescuento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/lbFecha"
android:layout_below="#id/txtFecha"
android:layout_marginTop="10sp"
android:text="#string/detalles_label_descuento"
android:textSize="18sp"
android:width="100dp" />
<TextView
android:id="#+id/txtDescuento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/lbDescuento"
android:layout_toRightOf="#id/lbDescuento"
android:text="#string/lorem_ipsum"
android:textSize="18sp" />
<TextView
android:id="#+id/lbLugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtDescuento"
android:layout_alignLeft="#id/lbDescuento"
android:layout_marginTop="10sp"
android:textSize="18sp"
android:text="#string/detalles_label_lugar"
android:width="60dp" />
<TextView
android:id="#+id/txtLugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/lbLugar"
android:layout_toRightOf="#id/lbLugar"
android:text="#string/lorem_ipsum"
android:textSize="18sp" />
<TextView
android:id="#+id/lbDescripcion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txtLugar"
android:layout_alignLeft="#id/lbLugar"
android:layout_marginTop="10sp"
android:textSize="18sp"
android:text="#string/detalles_label_descripcion"
android:width="125dp" />
<TextView
android:id="#+id/txtDescripcion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/lbDescripcion"
android:layout_alignLeft="#id/lbDescripcion"
android:layout_marginLeft="26dp"
android:layout_marginTop="6sp"
android:textSize="18sp" />
<ImageView
android:id="#+id/imgFotoEvento"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="#id/txtDescripcion"
android:contentDescription="#string/detalles_foto_evento"
android:gravity="center" />
</RelativeLayout>
And the Graphical Layout show the field 'lbTitulo' and 'txtTitulo' in top, and just below the fields 'lbFecha' and 'txtFecha' but the other fields are overlapping above the fields 'lbFecha' and 'txtFecha' (all together lbFecha, lbDescuento, lbLugar, lbDescripcion)...
Could someone say me what i'm doing wrong?
Tyvm!
In these type of scenarios I create a layout within a layout.
So each line of yours will be a layout and hence. You can only those elements in that line.
<?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="57dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/lblName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Name"
android:textSize="20dp" />
<EditText
android:id="#+id/txtName"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:ems="10"
android:gravity="left" >
<requestFocus />
</EditText>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="57dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/lblName1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Name"
android:textSize="20dp" />
<EditText
android:id="#+id/txtName1"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:ems="10"
android:gravity="left" >
</EditText>
</RelativeLayout>
Try to use LinearLayout Instead of RelativeLayout...

How can I place two TextView on a same line, in a vertical layout

I am trying to display an ImageView with 4 textView. "Title" "times" "age" and "informations". All of them are in global horizontal layout. And the 4 textView are in a vertical layout. The thing is that I want to have "times" and "age" one the same line. But it can't be with a vertical layout.
Here is my xml code :
<?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="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titre"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="age" />
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="age" />
<TextView
android:id="#+id/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textSize="8sp"
android:text="phrase" />
</LinearLayout>
Thanks
Here you go
<?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="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titre"
android:textSize="8sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:textSize="8sp" />
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="age"
android:textSize="8sp" />
</LinearLayout>
<TextView
android:id="#+id/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:text="phrase"
android:textSize="8sp" />
</LinearLayout>
Put LinearLayout as a parent to both textviews and set orientation of that LinearLayout as Horizontal..
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="time" />
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="age" />
<LinearLayout/>
as I told there is one more approach using Relative layout the second one
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="8sp"
android:textStyle="bold"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="time"
android:layout_below="#id/title" />
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8sp"
android:text="age"
android:layout_below="#id/title"
android:layout_toRightOf="#id/time" />
<TextView
android:id="#+id/information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textSize="8sp"
android:text="phrase"
android:layout_below="#id/time" />
Use the Graphical Layout, and place the age and the time fiels on the same ligne..much easier

Categories

Resources