I try to do this layout but i got only echec until now:
- 2 textview vertical Align sharing 50% width with 1 button.
- all must be vertical centered.
Here is the mockup showing what i want:
Mockup
Here is my actual code :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/PanelName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#color/colorBlack"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Parking Name"
android:textSize="14sp" />
<TextView
android:id="#+id/PanelAddress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#color/colorBlack"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Parking Address blablabla Paris"
android:textSize="14sp" />
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="#+id/btn_go"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:textColor="#color/colorAccent"
android:layout_marginTop="30dp"
android:layout_marginBottom="24dp"
android:layout_marginRight="24dp"
android:padding="12dp"
android:text="GO !"/>
</LinearLayout>
Thanks for help :)
Remove Nested Linear Layouts it's bad for performance. I have made some changes in your Layout. Make your AppCompatButton Layout inside Relative Layout and make it's width to android:layout_width="wrap_content" and also Remove First Linear Layout inside Root Layout.
Refer this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/image_area"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/btn_go"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/PanelName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Parking Name"
android:textColor="#000"
android:textSize="14sp" />
<TextView
android:id="#+id/PanelAddress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:text="Parking Address blablabla Paris Parking Address blablabla Paris Parking Address blablabla Paris"
android:textColor="#000"
android:textSize="14sp" />
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="#+id/btn_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="24dp"
android:layout_marginRight="24dp"
android:layout_marginTop="30dp"
android:layout_weight="2"
android:background="#000"
android:padding="12dp"
android:text="GO !"
android:textColor="#FFF" />
</RelativeLayout>
Here is Screen.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/txtOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView One" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/txtTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView Two" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="#+id/btnSomething"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Related
here i have used scroll view and I want to make a space in the bottom of page so only terms and conditions can scroll and checkable box and button does not scroll it should be in the bottom of page can you help me with the xml. I have attached a image I want a design like this where buttons at the bottom not moves Design Example herea
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Common.PolcyPage">
<LinearLayout
android:id="#+id/liner_layout_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:layout_marginLeft="35dp"
android:layout_marginTop="60dp"
android:fontFamily="#font/segoe_ui_bold"
android:text="#string/terms_of_services"
android:textColor="#color/colorTandC"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:layout_marginLeft="35dp"
android:text="#string/updated_date_terms"
android:textColor="#color/colorTandC_titles" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="38dp"
android:background="#color/colorTandC_desc" />
</LinearLayout>
<ScrollView
android:scrollbars="none"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:layout_marginLeft="35dp"
android:layout_marginTop="35dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/segoe_ui_semibold"
android:text="#string/terms_one_title"
android:textColor="#color/colorTandC_titles"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:text="#string/terms_one_desc"
android:textColor="#color/colorTandC_desc"
android:textSize="13sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:fontFamily="#font/segoe_ui_semibold"
android:text="#string/terms_two_title"
android:textColor="#color/colorTandC_titles"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:text="#string/terms_two_desc"
android:textColor="#color/colorTandC_desc"
android:textSize="13sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginLeft="25dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:text="#string/terms_two_desc_terms"
android:textColor="#color/colorTandC_desc"
android:textSize="13sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
Try adding Buttons at the bottom of screen & even below of Scroll view
Add this lime in scrollView or Parent LinearLayout
<ScrollView>
android:layout_above="#+id/bottom_panel"
Add this at the very bottom of your xml
</ScrollView>
</LinearLayout>
--------------- ADD HERE - Below Scroll View -------
<LinearLayout
android:id="#+id/bottom_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom" OR android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Decline"/>
<Button
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Accept"/>
</LinearLayout>
</RelativeLayout>
Let me know if its working fine or not
If I correctly understand your question, you can make it like 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">
<LinearLayout
android:id="#+id/bottom_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:gravity="center"
android:orientation="horizontal">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="I agree with the Terms and Conditions"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:gravity="center"
android:orientation="horizontal">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="I agree with the Privacy Policy"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:paddingTop="16dp"
android:paddingBottom="32dp"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:layout_marginRight="32dp"
android:text="decline"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="accept"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/top_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:paddingTop="16dp"
android:paddingBottom="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="#drawable/your_image"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Terms of service"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Update date"/>
</LinearLayout>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottom_parent"
android:layout_below="#id/top_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- ADD YOUR TEXTVIEWS HERE -->
</LinearLayout>
</ScrollView>
use android:layout_above and android:layout_below to define your ScrollView position
For example, I have a vertical linear layout with 2 buttons which have android:layout_weight="1" inside. The problem is that if I add a new line to the button text using
and increase its size, that button becomes bigger than another one. How to make a button to not change its size if the text size was changed?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ACC1"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="#+id/button18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/colorofbuttons"
android:fontFamily="#font/architects_daughter"
android:text="Mom"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp"></Button>
<Button
android:id="#+id/button19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/colorofbuttons"
android:ellipsize="end"
android:fontFamily="#font/architects_daughter"
android:maxLines="1"
android:text="My
Name"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="#+id/button20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/colorofbuttons"
android:fontFamily="#font/architects_daughter"
android:text="Dad"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
<Button
android:id="#+id/button21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#drawable/colorofbuttons"
android:fontFamily="#font/architects_daughter"
android:text="Girl"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
In your button code REPLACE
android:layout_height="wrap_content"
With
android:layout_height="0dp"
it will work :)
Replace this in your XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ACC1"
android:weightSum="2"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:weightSum="1"
android:orientation="vertical">
<Button
android:id="#+id/button18"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight=".5"
android:text="Mom"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp"/>
<Button
android:id="#+id/button19"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight=".5"
android:ellipsize="end"
android:maxLines="1"
android:text="My
Name"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:weightSum="1"
android:orientation="vertical">
<Button
android:id="#+id/button20"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight=".5"
android:text="Dad"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
<Button
android:id="#+id/button21"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="10dp"
android:layout_weight=".5"
android:text="Girl"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
I have 4 TextViews. What I'm trying to do is to make all guests in the list take equal space (except the 'VIP List' TextView).
So I've set layout_height to 0dp and layout_weight to 1 but there is still some place not taken in the bottom.
What is wrong with my code?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray">
<TextView
android:text="VIP List"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ACC1"
android:textSize="24sp"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:gravity="center" />
<TextView
android:text="Bob"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#BF360C"
android:textSize="24sp"
android:textColor="#FFFFFF"/>
<TextView
android:text="Bill"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#4CAF50"
android:textSize="24sp"
android:textColor="#FFFFFF"/>
<TextView
android:text="Ben"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#2E7D32"
android:textSize="24sp"
android:textColor="#FFFFFF"/>
</LinearLayout>
Change your LinearLayout code with this;
<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="3"
android:background="#android:color/darker_gray">
...
</LinearLayout>
Put out "VIP List" TextView from content container LinearLayout because it is not part of "relative" TextView group, then add
android:weightSum="3" to LinearLayout content container because you have 3 TextViews with weight = 1. Finally wrap all view within a parent LinearLayout.
Consider something like below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ACC1"
android:gravity="center"
android:text="VIP List"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:weightSum="3"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#BF360C"
android:text="Bob"
android:textColor="#FFFFFF"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#4CAF50"
android:text="Bill"
android:textColor="#FFFFFF"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#2E7D32"
android:text="Ben"
android:textColor="#FFFFFF"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
It will work.. Use a Linear layout under the parent layout and it android:weightSum="3" and just put the vip list outside of second linear layout Like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00ACC1"
android:gravity="center"
android:text="VIP List"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:weightSum="3"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#BF360C"
android:text="Bob"
android:textColor="#FFFFFF"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#4CAF50"
android:text="Bill"
android:textColor="#FFFFFF"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#2E7D32"
android:text="Ben"
android:textColor="#FFFFFF"
android:textSize="24sp" />
</LinearLayout>
</LinearLayout>
I have a dialog with layout
subject_view.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:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<TextView
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="Subject"
android:textSize="18sp"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/subject_name"/>
<LinearLayout
android:weightSum="2"
android:gravity="end"
android:layout_below="#id/subject_name"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ViewSwitcher
android:layout_weight="1"
android:layout_marginTop="8dp"
android:layout_below="#id/subject_name"
android:id="#+id/switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_gravity="center"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:paddingLeft="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/please_wait"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:id="#+id/studentRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</ViewSwitcher>
<Button
android:layout_weight="1"
android:layout_below="#id/switcher"
android:layout_alignParentRight="true"
android:id="#+id/ok_Btn"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:background="#drawable/blue_button"
android:text="ok"
android:textColor="#fff"/>
</LinearLayout>
</RelativeLayout>
When the dialog is created, I am fetching data from server to populate RecyclerView. At that time ViewPager's first child (with the progressbar) is visible. When I get data from server I set RecyclerView as visible child.
The problem here is, when RecyclerView have a lot of rows, the button under under ViewSwitcher containing the RecyclerView is only partially visible (Like, one third of the button is not visible).
Screenshot (How it is not supposed to look)
But when the recyclerView doesn't have that much rows its showing as expected,
Screenshot (How it is supposed to look)
How can I solve this?
Whenever you are adding weight for linear layout point to keep in mind are:
Give android:weightSum="1" as one and child layout weight from 0.0 to 1.0
ex:android:layout_weight="0.3"
Use layout weight as 0dp instead pf hardcoded value ex: android:layout_height="0dp" instead of android:layout_height="30dp"
Try this layout instead.Hope it works
<?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="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp">
<TextView
android:id="#+id/subject_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="Subject"
android:textColor="#color/black"
android:textSize="18sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/subject_name"
android:gravity="end"
android:orientation="vertical"
android:weightSum="1">
<ViewSwitcher
android:id="#+id/switcher"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#id/subject_name"
android:layout_marginTop="8dp"
android:layout_weight="0.9">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:text="#string/please_wait" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/studentRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"></android.support.v7.widget.RecyclerView>
</ViewSwitcher>
<Button
android:id="#+id/ok_Btn"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_alignParentRight="true"
android:layout_below="#id/switcher"
android:layout_weight="0.1"
android:background="#drawable/blue_button"
android:text="ok"
android:textColor="#fff" />
</LinearLayout>
You should maintain your weightSum and weight properly in layout.for more knowledge you may check this solution and apply like this
<LinearLayout
android:weightSum="2"
android:gravity="end"
android:layout_below="#id/subject_name"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ViewSwitcher
android:layout_weight="1.5"
android:layout_marginTop="8dp"
android:layout_below="#id/subject_name"
android:id="#+id/switcher"
android:layout_width="match_parent"
android:layout_height="0dp">
<LinearLayout
android:layout_gravity="center"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:paddingLeft="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/please_wait"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:id="#+id/studentRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</ViewSwitcher>
<Button
android:layout_weight="0.5"
android:layout_below="#id/switcher"
android:layout_alignParentRight="true"
android:id="#+id/ok_Btn"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:background="#drawable/blue_button"
android:text="ok"
android:textColor="#fff"/>
</LinearLayout>
use android:layout_marginBottom="30dp" in recycle view
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:layout_marginBottom="30dp"
android:id="#+id/studentRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
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:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<TextView
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="Subject"
android:textSize="18sp"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/subject_name"/>
<RelativeLayout
android:layout_below="#id/subject_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ViewSwitcher
android:layout_marginTop="8dp"
android:id="#+id/switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_gravity="center"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:paddingLeft="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/please_wait"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:id="#+id/studentRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</ViewSwitcher>
<Button
android:layout_below="#id/switcher"
android:layout_alignParentRight="true"
android:id="#+id/ok_Btn"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:background="#drawable/blue_button"
android:text="ok"
android:textColor="#fff"/>
</RelativeLayout>
Ok Check now!
<?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:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<TextView
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="Subject"
android:textSize="18sp"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/subject_name"/>
<RelativeLayout
android:layout_below="#id/subject_name"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ViewSwitcher
android:layout_marginTop="8dp"
android:id="#+id/switcher"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_gravity="center"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:paddingLeft="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please wait"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:id="#+id/studentRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</ViewSwitcher>
<Button
android:layout_weight="1"
android:layout_alignParentRight="true"
android:id="#+id/ok_Btn"
android:layout_below="#id/switcher"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:background="#369"
android:text="OK"
android:textColor="#fff"/>
</RelativeLayout>
</RelativeLayout>
I am trying to create a screen that shows the details of the students. The following is my xml code for that screen.
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".PatientDetails">
<LinearLayout
android:id="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="3"
android:background="#color/BackgroundColor">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Details"
android:textColor="#color/white"
android:textSize="30dp"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:background="#color/white">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Name"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#color/BackgroundColor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/PatientName"
android:text="Joseph"
android:layout_weight="1"
android:textSize="20dp"
android:textColor="#color/BackgroundColor"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#color/BackgroundColor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/age"
android:text="21"
android:layout_weight="1"
android:textSize="20dp"
android:textColor="#color/BackgroundColor"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sex"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#color/BackgroundColor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Sex"
android:text="Female"
android:layout_weight="1"
android:textSize="20dp"
android:textColor="#color/BackgroundColor"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
The output of the code is as follows:
Can someone tell me how to modify the code so that the values on the right hand side of each row are aligned properly.
Row example:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Student Name"
android:textColor="#color/BackgroundColor"
android:textSize="20dp" />
<TextView
android:id="#+id/PatientName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Joseph"
android:textColor="#color/BackgroundColor"
android:textSize="20dp" />
</LinearLayout>
Remove android:layout_weight="1" from row root. Change android:layout_width="wrap_content" to android:layout_width="0dp"
Sample
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:text="Student Name"
android:textColor="#color/pika_bg"
android:textSize="20dp" />
<TextView
android:id="#+id/PatientName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="Joseph"
android:textColor="#color/pika_bg"
android:textSize="20dp" />
</LinearLayout>
Here I am added android:weightSum="2"to the parent LinearLayout. So that the child views can get same width. Then we can adjust padding/gravity attributes according to your needs.
I think you use linear layout but linear layout have also one property its called layout_weight i think you should use this.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Test" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Test" />
</LinearLayout>