When I'm trying to add ScrollView its giving me error that Scroll view can contain only a single child. So how to add a ScrollView ?
And also when I open my app in various phones all the phones gives different layouts. How do manage the look and feel of the app same for all mobile devices ?
Register.xml
<?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="match_parent"
android:layout_height="match_parent"
android:background="#0066CC"
android:orientation="vertical"
android:padding="10dp" >
<ImageView
android:id="#+id/upImage"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView1"
android:layout_width="465dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_weight="0.02"
android:layout_marginBottom="100dp"
android:textSize="15sp"
android:textStyle="bold"
android:text="Tap to upload Profile Picture" />
<EditText
android:id="#+id/imName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:hint="Enter name of the Image"
android:ems="10" >
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
<EditText
android:id="#+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age" />
<EditText
android:id="#+id/etAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="#+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textPassword" />
<Button
android:id="#+id/bRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
</LinearLayout>
Yes ScrollView allow only single child
So put you parent LinearLayout inside ScrollView like below
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0066CC"
android:orientation="vertical"
android:padding="10dp" >
<ImageView
android:id="#+id/upImage"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#000"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textView1"
android:layout_width="465dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_weight="0.02"
android:layout_marginBottom="100dp"
android:textSize="15sp"
android:textStyle="bold"
android:text="Tap to upload Profile Picture" />
<EditText
android:id="#+id/imName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:hint="Enter name of the Image"
android:ems="10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name" />
<EditText
android:id="#+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age" />
<EditText
android:id="#+id/etAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="#+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textPassword" />
<Button
android:id="#+id/bRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
</LinearLayout>
</ScrollView>
Android only supports a single child inside a ScrollView. The simplest way is to enclose everything inside a LinearLayout and make it a child of a ScrollView.
If you however want to maintain the same look and feel throughout the application, try using a RelativeLayout instead of the LinearLayout as the child of the ScrollView.
Related
I have Relative layout the is set to wrap_content in height. It has 2 TextView and 2 EditText. However, the RelativeLayout does not match to the height of EditTexts.
Dashed Rectangle is the region highlighted by android studio preview tool as the borders of RelativeLayout.
The actual problem is that when I run the app the bottom edittext kind of goes below the Relative layout and so its bottom part disappears. Thereby, user can't see that bottom line and don't know that there is a textfield.
Android Studio Preview:
Problem and Result on Emulator:
XML file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<android.support.v4.widget.Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="5" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/numberOfDaysTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/initialNumberOfDays"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="58sp" />
<TextView
android:id="#+id/daysText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/numberOfDaysTextView"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="#string/daysText"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
</RelativeLayout>
<android.support.v4.widget.Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="3" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/fromDatePickerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="#string/fromTextView"
android:textSize="15sp" />
<EditText
android:id="#+id/fromDate"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/fromDatePickerTextView"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:layout_toEndOf="#+id/fromDatePickerTextView"
android:layout_toRightOf="#+id/fromDatePickerTextView"
android:ems="10"
android:focusableInTouchMode="false"
android:inputType="date" />
<TextView
android:id="#+id/toDatePickerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/fromDatePickerTextView"
android:layout_alignRight="#+id/fromDatePickerTextView"
android:layout_below="#+id/fromDatePickerTextView"
android:layout_marginTop="32dp"
android:text="#string/toTextView"
android:textSize="15sp" />
<EditText
android:id="#+id/toDate"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/toDatePickerTextView"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:layout_marginTop="22dp"
android:layout_toEndOf="#+id/toDatePickerTextView"
android:layout_toRightOf="#+id/toDatePickerTextView"
android:ems="10"
android:focusableInTouchMode="false"
android:inputType="date" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/calculateDaysButton"
android:layout_width="160dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="40dp"
android:background="#drawable/button_bg"
android:text="#string/calculateButtonText"
android:textColor="#android:color/white" />
</RelativeLayout>
</LinearLayout>
EDIT: Another solution that has worked:
TextView must be aligned to baseline of EditText and not the reverse way!
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/fromDatePickerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBaseline="#+id/fromDate"
android:text="#string/fromTextView"
android:textSize="15sp" />
<EditText
android:id="#+id/fromDate"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:layout_toEndOf="#+id/fromDatePickerTextView"
android:layout_toRightOf="#+id/fromDatePickerTextView"
android:ems="10"
android:focusableInTouchMode="false"
android:inputType="date" />
<TextView
android:id="#+id/toDatePickerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/fromDatePickerTextView"
android:layout_alignRight="#+id/fromDatePickerTextView"
android:layout_alignBaseline="#+id/toDate"
android:layout_marginTop="32dp"
android:text="#string/toTextView"
android:textSize="15sp" />
<EditText
android:id="#+id/toDate"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:layout_marginTop="10dp"
android:layout_toEndOf="#+id/toDatePickerTextView"
android:layout_toRightOf="#+id/toDatePickerTextView"
android:layout_below="#+id/fromDate"
android:ems="10"
android:focusableInTouchMode="false"
android:inputType="date" />
</RelativeLayout>
You should use Linear Layout instead of Relative Layout.
Check out below code i have done some modification and applied with Linear Layout. You can modify with margin , height , width.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<android.support.v4.widget.Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="5" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/numberOfDaysTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="0"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="58sp" />
<TextView
android:id="#+id/daysText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/numberOfDaysTextView"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Day"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15sp" />
</RelativeLayout>
<android.support.v4.widget.Space
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="3" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/fromDatePickerTextView"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="to"
android:textSize="15sp" />
<EditText
android:id="#+id/fromDate"
android:layout_width="130dp"
android:layout_height="45dp"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:ems="10"
android:focusableInTouchMode="false"
android:inputType="date" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/toDatePickerTextView"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="feom"
android:textSize="15sp" />
<EditText
android:id="#+id/toDate"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:layout_marginTop="22dp"
android:ems="10"
android:focusableInTouchMode="false"
android:inputType="date" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/calculateDaysButton"
android:layout_width="160dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:layout_marginTop="40dp"
android:background="#drawable/button_bg"
android:text="#string/calculateButtonText"
android:textColor="#android:color/white" />
</RelativeLayout>
</LinearLayout>
Hope this Solves your problem.
Can you try this code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/fromDatePickerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="from"
android:textSize="15sp"
android:layout_above="#+id/toDate"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:id="#+id/fromDate"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:ems="10"
android:focusableInTouchMode="false"
android:inputType="date"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/toDate"
android:layout_alignStart="#+id/toDate" />
<TextView
android:id="#+id/toDatePickerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="to"
android:textSize="15sp"
android:layout_alignBottom="#+id/toDate"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:id="#+id/toDate"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_below="#+id/fromDate"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp"
android:layout_toEndOf="#+id/toDatePickerTextView"
android:layout_toRightOf="#+id/toDatePickerTextView"
android:ems="10"
android:focusableInTouchMode="false"
android:inputType="date" />
</RelativeLayout>
You made a fixed size for edittext, try removing those so that you can achieve your expectations. Also use singleline=true/maxLines=1 for edit text- this is best practice.
I've created a form using LinearLayout. All the objects appear fine, except for two buttons.
I'm trying to align them in a there own LinearLayout, but for some reason one of them is always lower than the other.
<?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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="il.ac.shenkar.david.todolistex2.InviteMember"
tools:showIn="#layout/activity_invite_member">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:id="#+id/invitememberLayout1">
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Invite Team Members"
android:id="#+id/invitememebrsView"
android:textSize="32sp"
android:layout_alignTop="#+id/invitememberLayout1"
android:layout_centerHorizontal="true"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:paddingLeft="25dp"
android:orientation="vertical"
android:id="#+id/invitememberLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Enter Team Member Email"
android:layout_marginTop="60dp"
android:paddingLeft="45dp"
android:id="#+id/memberemail"
android:layout_alignTop="#+id/createteamLayout2"
android:layout_centerHorizontal="true"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="8"
android:minLines="1"
android:layout_marginTop="20dp"
android:hint=" mycool#emailaddress.com"
android:inputType="textEmailAddress"
android:digits="0,1,2,3,4,5,6,7,8,9,qwertzuiopasdfghjklyxcvbnmABCDEFGHIJKLMNOPQRSTUVWXYZ,#,."
android:textSize="16sp"
android:id="#+id/editemailaddress" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Phone Number"
android:layout_marginTop="30dp"
android:paddingLeft="85dp"
android:id="#+id/memberphonetextView"
android:layout_alignTop="#+id/invitememberLayout2"
android:layout_centerHorizontal="true"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:maxLength="10"
android:textSize="16sp"
android:hint=" Only digits allowed"
android:id="#+id/memberuserphonenumber" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Invite Member"
android:layout_marginTop="20dp"
android:layout_marginLeft="80dp"
android:layout_alignTop="#+id/createteamLayout2"
android:id="#+id/invitebtn"
android:onClick="onInviteMember" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="370dp"
android:orientation="vertical"
android:id="#+id/invitememberLayout4">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:id="#+id/Donebtn"
android:onClick="onDonebtn"
android:layout_gravity="right" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:id="#+id/Exitbtn"
android:onClick="onExitbtn"/>
</LinearLayout>
Here is the UI
It's bcz you have defined orientation to vertical.
Replace this code in your XML.
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="il.ac.shenkar.david.todolistex2.InviteMember"
tools:showIn="#layout/activity_invite_member">
<LinearLayout
android:id="#+id/invitememberLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"></LinearLayout>
<TextView
android:id="#+id/invitememebrsView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/invitememberLayout1"
android:layout_centerHorizontal="true"
android:text="Invite Team Members"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="32sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/invitememberLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:orientation="vertical"
android:paddingLeft="25dp">
<TextView
android:id="#+id/memberemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/createteamLayout2"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:paddingLeft="45dp"
android:text="Enter Team Member Email"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<EditText
android:id="#+id/editemailaddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:digits="0,1,2,3,4,5,6,7,8,9,qwertzuiopasdfghjklyxcvbnmABCDEFGHIJKLMNOPQRSTUVWXYZ,#,."
android:hint=" mycool#emailaddress.com"
android:inputType="textEmailAddress"
android:lines="8"
android:minLines="1"
android:textSize="16sp" />
<TextView
android:id="#+id/memberphonetextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/invitememberLayout2"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:paddingLeft="85dp"
android:text="Phone Number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<EditText
android:id="#+id/memberuserphonenumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint=" Only digits allowed"
android:inputType="phone"
android:maxLength="10"
android:textSize="16sp" />
<Button
android:id="#+id/invitebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/createteamLayout2"
android:layout_marginLeft="80dp"
android:layout_marginTop="20dp"
android:onClick="onInviteMember"
android:text="Invite Member" />
</LinearLayout>
<LinearLayout
android:id="#+id/invitememberLayout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="370dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2">
<Button
android:id="#+id/Donebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:onClick="onDonebtn"
android:text="Done" />
<Button
android:id="#+id/Exitbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onExitbtn"
android:text="Exit" />
</LinearLayout>
</RelativeLayout>
And it's Done.
Because you gave the LinearLayout which contains the buttons a vertical orientation, change it to horizontal
android:orientation="horizontal"
In your LinearLayout which contains the 2 buttons -
replace -
android:orientation="vertical"
with
android:orientation="horizontal"
Because you want your buttons to be arranged horizontally.
Orientation in LinearLayout means One after another
So don't use orientation vertical in last LinearLayout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="370dp"
android:orientation="horizontal"
android:id="#+id/invitememberLayout4">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:id="#+id/Donebtn"
android:onClick="onDonebtn"
android:layout_gravity="right" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:id="#+id/Exitbtn"
android:onClick="onExitbtn"/>
</LinearLayout>
Or other way you can do this is to change LinearLayout with buttons with RelativeLayout like that
<RelativeLayout
android:id="#+id/invitememberLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="370dp">
<Button
android:id="#+id/Donebtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onDonebtn"
android:layout_alignParentRight="true"
android:text="Done"/>
<Button
android:id="#+id/Exitbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onExitbtn"
android:layout_alignParentLeft="true"
android:text="Exit"/>
</RelativeLayout>
in last linearlayout which contain done and exit . set -
android:orientation="Horizontal"
let me know if it helps you.
Add android:orientation="horizontal" in last LinearLayout. And If you want to align these two buttons left and right side I suggest you to use RelativeLayout instead of LinearLayout.
Try this one :
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="370dp"
android:orientation="horizontal"
android:id="#+id/invitememberLayout4"
android:weightSum="3">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Invite Member"
android:layout_marginTop="20dp"
android:layout_marginLeft="80dp"
android:layout_alignTop="#+id/createteamLayout2"
android:id="#+id/invitebtn"
android:onClick="onInviteMember"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Done"
android:id="#+id/Donebtn"
android:onClick="onDonebtn"
android:layout_gravity="right"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:id="#+id/Exitbtn"
android:onClick="onExitbtn"
android:layout_weight="1"/>
</LinearLayout>
I have a layout like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fsfsdfds"
android:layout_gravity="center_vertical" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fdsfdsfds"
android:layout_gravity="center_vertical" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
It fill the whole space of the activity.
How can I make these 2 TextViews and EditTexts take only space enough to show themselves (not fill all the space) and align the button to the bottom?
I think this is what you're looking for :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/LinearLayout1"
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:layout_gravity="center_vertical"
android:text="TextView1" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/LinearLayout1"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TextView2" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:inputType="text" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" />
</RelativeLayout>
EDIT :
If you don't want to use the two LinerLayouts (and therefore gain even more performance), you can do the following :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/TextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/EditText1"
android:layout_gravity="center_vertical"
android:text="TextView1" />
<EditText
android:id="#+id/EditText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:layout_toEndOf="#id/TextView1"
android:layout_toRightOf="#id/TextView1"
android:inputType="text" />
<TextView
android:id="#+id/TextView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#id/EditText2"
android:layout_below="#id/TextView1"
android:layout_gravity="center_vertical"
android:text="TextView2" />
<EditText
android:id="#+id/EditText2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/EditText1"
android:layout_gravity="center_vertical"
android:layout_toEndOf="#id/TextView2"
android:layout_toRightOf="#id/TextView2"
android:inputType="text" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button" />
</RelativeLayout>
Check This.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5"
android:text="fsfsdfds" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5"
android:text="fdsfdsfds" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.5" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
You try with RelativeLayout, or else if wanted to be done with LinearLayout you need to consider weights if width is not fillparent.
Check below sample to start with ..
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.2"
android:text="fsfsdfds" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.8" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.2"
android:text="fdsfdsfds" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.8" />
Either convert to a relative-layout and use alignparentbottom for the button - or use layout weights for the linear-layouts
I have added some widgets on activity_main.xml, a layout file for main.java in android. When I ran the program on emulator, the last widget is missing in the emulator screen. What will be the reason? How to rectify it?
Here by I am giving below the code for activity_main.xml
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg1"
android:paddingBottom="50dp">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:src="#drawable/cmplnlogo"
android:id="#+id/imageViewLogo" />
<EditText
android:layout_marginTop="30dp"
android:layout_width="310dp"
android:layout_height="50dp"
android:layout_marginLeft="30dp"
android:inputType="textEmailAddress"
android:hint="#string/signupUserHint"
android:textSize="15sp"
android:gravity="center"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextEmail" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewEmailValidator" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextPwd" />
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupCfmPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextConfirmPwd" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewPwdValidator" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/signInHint"
android:onClick="GoToLogin"
android:textColor="#FFFFFF"
android:id="#+id/textViewSignin" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/edittextstyle"
android:text="#string/SignUp"
android:onClick="SignUp"
android:textColor="#FFFFFF"
android:id="#+id/buttonSignUp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/service_terms"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textViewServiceTerms" />
</LinearLayout>
</LinearLayout>
I solved the problem mentioned in the above question by adding scrollview widget. I added the scrollview widget in the layout file for which all widgets are not appearing on the emulator. Remember scrollview only suppors only one direct file.
I had many layouts inside the layout file that enclosed different widgets. I enclosed all the layouts with in one layout. And then, enclosed that layout with scrollview. I am giving the snippet.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/scroll">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:id="#+id/registerUserName"
android:paddingBottom="10dp"
android:layout_weight="1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/enterRegisterUserName"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</Scrollview>
Name, password1 field not showing up in scrollview
everything else working properly
here is my xml for it..
Made a linear layout after scrollview as it supports only one child.
Any idea what is the problem ?
<?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="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Name" />
<EditText
android:id="#+id/password1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword" />
<EditText
android:id="#+id/password2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/retype"
android:inputType="textPassword" />
<EditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/email"
android:inputType="textEmailAddress" />
<TextView
android:id="#+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender" />
<RadioGroup
android:id="#+id/radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
<RadioButton
android:id="#+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<ImageView
android:id="#+id/capcha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/typecaptcha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Type" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
</ScrollView>
</LinearLayout>
For me the Password field works, seems fine (I copied you XML to test it). If you use eclipse try Project>Clean. I had similar Problems.
Happy Coding
EDIT(Result):