Android Scroll View not filling Device Screen - android

Hello I have a fragment that loads an Xml file. The xml file code is given below.
<?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="fill_parent"
android:orientation="vertical"
android:scrollbars="vertical"
android:background="#2f3799"
android:fillViewport="true"
tools:context=".NewItem"
android:paddingEnd="0dp"
android:paddingStart="0dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#111a42"
android:weightSum="1">
<TextView
android:layout_width="fill_parent"
android:layout_height="60dp"
android:text="SUBMIT YOUR POST"
android:id="#+id/textHeading"
android:textSize="15pt"
android:textColor="#ffffff"
android:textAlignment="center"
android:layout_weight="20" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Category"
android:textColor="#ffffff"
android:id="#+id/textCategory"
android:layout_alignParentStart="true"
android:layout_marginTop="36dp" />
<GridLayout
android:id="#+id/gridLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioGroup
android:id="#+id/categoryRadio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/motoRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#ffffff"
android:text="Motorbike" />
<RadioButton
android:id="#+id/carRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#ffffff"
android:text="Car" />
<RadioButton
android:id="#+id/otherRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Others"
android:textColor="#ffffff"/>
</RadioGroup>
</GridLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Title"
android:textColor="#ffffff"
android:id="#+id/textTitle" />
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#drawable/edittext_bg"
android:id="#+id/titleText"
android:inputType="text"
android:hint="Item Title"
android:singleLine="true"
android:visibility="visible"
android:typeface="sans"
android:layout_weight="0.65"
android:layout_marginLeft="10dp"
android:layout_gravity="left"
android:layout_below="#id/textTitle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Subject"
android:textColor="#ffffff"
android:id="#+id/textSubject" />
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:inputType="text"
android:background="#drawable/edittext_bg"
android:id="#+id/subjectText"
android:singleLine="true"
android:visibility="visible"
android:layout_marginLeft="10dp"
android:typeface="sans"
android:hint="Item Subject"
android:layout_weight="0.65"
android:layout_gravity="left" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Content"
android:textColor="#ffffff"
android:id="#+id/textContent"
android:layout_below="#+id/subjectText"/>
<EditText
android:layout_width="300dp"
android:layout_height="100dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/contentText"
android:background="#drawable/edittext_bg"
android:layout_marginLeft="10dp"
android:textAlignment="textStart"
android:textColor="#232121"
android:layout_below="#id/textContent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Source"
android:textColor="#ffffff"
android:id="#+id/textSource"
android:layout_below="#+id/contentText"/>
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:inputType="text"
android:background="#drawable/edittext_bg"
android:id="#+id/sourceText"
android:layout_marginLeft="10dp"
android:layout_above="#+id/button"
android:layout_below="#+id/textSource"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SUBMIT"
android:textColor="#ffffff"
android:id="#+id/button"
android:onClick="submitItem"
android:layout_gravity="center" />
</LinearLayout>
</ScrollView>
Even after setting the android:fillViewport="true", the view does not fill the entire device screen. See the picture below for clarity. Awaiting your response. Thanks

It seems you've the default paddings, check your activity layout and delete these lines:
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"

change your dimens file
<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>
then in the layout
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"

Delete all padding lines from your xml

Your activity file contains Padding in main layout tag.

Related

Buttons in layout are crammed to left side of screen

I have two buttons (Next and Cancel) in my layout that are crammed to the left side of the screen and it won't allow me to adjust them past the centre. I tried playing around with the attributes of the buttons to fix it, I even considered placing these buttons in a linear layout in order to organize them with no luck.
I've attached my .xml file, I would really appreciate it if someone can point out where I'm going wrong.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<EditText
android:id="#+id/emailAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:text="Email"
android:layout_marginTop="79dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/mobileNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:text="Mobile"
android:layout_alignParentStart="true"
android:layout_below="#+id/emailAddress"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="Password"
android:layout_alignParentStart="true"
android:layout_below="#+id/mobileNum"
android:layout_centerHorizontal="true" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="23dp"
android:layout_below="#+id/password"
android:layout_above="#+id/loginButton"
android:layout_alignEnd="#+id/password">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rider"
android:id="#+id/riderRadioButton"
android:layout_alignTop="#+id/driverRadioButton"
android:layout_toEndOf="#+id/driverRadioButton"
android:layout_alignBottom="#+id/driverRadioButton"
android:checked="false"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Driver"
android:id="#+id/driverRadioButton"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:checked="false"
android:onClick="onRadioButtonClicked" />
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Your email and number are used to send you ride confirmations"
android:id="#+id/messageTextView"
android:layout_below="#+id/password"
android:layout_centerHorizontal="true"
android:layout_marginTop="79dp"
android:textAlignment="center"
android:textSize="13dp"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/messageTextView">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/nextButton"
android:layout_marginTop="35dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="#+id/cancelButton"
android:layout_marginEnd="85dp"/>
</LinearLayout>
At the time, I didn't have experience with xml files. However, I have been able to fix it now. I removed the LinearLayout which contained the buttons, and played around with some attributes to get it to work.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="daniaghazal.com.hitchhikr.SignUpPage">
<EditText
android:id="#+id/emailAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Email"
android:layout_marginTop="79dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/mobileNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:hint="Mobile"
android:layout_alignParentStart="true"
android:layout_below="#+id/emailAddress"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Password"
android:layout_alignParentStart="true"
android:layout_below="#+id/mobileNum"
android:layout_centerHorizontal="true" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="23dp"
android:layout_below="#+id/password"
android:checkedButton="#+id/riderRadioButton"
android:layout_alignBottom="#+id/messageTextView"
android:layout_alignParentEnd="true">
<RadioButton
android:id="#+id/riderRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rider"
android:layout_alignTop="#+id/driverRadioButton"
android:layout_toEndOf="#+id/driverRadioButton"
android:layout_alignBottom="#+id/driverRadioButton"
android:checked="false"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:id="#+id/driverRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Driver"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:checked="false"
android:onClick="onRadioButtonClicked" />
</RadioGroup>
<TextView
android:id="#+id/messageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Your email and number are used to send you ride confirmations"
android:layout_below="#+id/password"
android:layout_centerHorizontal="true"
android:layout_marginTop="79dp"
android:textAlignment="center"
android:textSize="13dp"/>
<Button
android:id="#+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:layout_marginLeft="75dp"
android:layout_marginTop="20dp"
android:layout_below="#+id/messageTextView"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_marginTop="20dp"
android:layout_below="#+id/radioGroup"
android:layout_toEndOf="#+id/nextButton" />
</RelativeLayout>
Try to set android:gravity attribute of parent layout to center it's content. Something like:
EDIT
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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">
<EditText
android:id="#+id/emailAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:text="Email"
android:layout_marginTop="79dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<EditText
android:id="#+id/mobileNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:text="Mobile"
android:layout_alignParentStart="true"
android:layout_below="#+id/emailAddress"
android:layout_centerHorizontal="true"/>
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="Password"
android:layout_alignParentStart="true"
android:layout_below="#+id/mobileNum"
android:layout_centerHorizontal="true"/>
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_marginTop="23dp"
android:layout_below="#+id/password"
android:checkedButton="#+id/riderRadioButton"
android:layout_alignBottom="#+id/messageTextView"
android:layout_alignParentEnd="true">
<RadioButton
android:id="#+id/riderRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rider"
android:layout_alignTop="#+id/driverRadioButton"
android:layout_toEndOf="#+id/driverRadioButton"
android:layout_alignBottom="#+id/driverRadioButton"
android:checked="false"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:id="#+id/driverRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Driver"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:checked="false"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Your email and number are used to send you ride confirmations"
android:id="#+id/messageTextView"
android:layout_below="#+id/password"
android:layout_centerHorizontal="true"
android:layout_marginTop="79dp"
android:textAlignment="center"
android:textSize="13dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/messageTextView"
android:layout_marginTop="20dp"
android:gravity="center_horizontal">
<Button
android:id="#+id/nextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"/>
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"/>
</LinearLayout>
</RelativeLayout>

How to align textview in wrap content right for bigger screen in android studio?

[My Layout]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".Login"
android:background="#drawable/background">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/efield"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/textView_username" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Username :"
android:id="#+id/textView_username"
android:textColor="#FFFFFF"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:layout_above="#+id/textView_attempt"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="right"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Password :"
android:id="#+id/textView_password"
android:textColor="#FFFFFF"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_above="#+id/textView_attempt_count"
android:layout_alignRight="#id/editText_pass"
android:layout_alignEnd="#id/editText_pass"
android:gravity="right" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editText_user"
android:text="Name"
android:textColor="#FFFFFF"
android:layout_alignTop="#+id/textView_username"
android:layout_alignRight="#+id/imageView"
android:layout_alignEnd="#+id/imageView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editText_password"
android:text="Password"
android:textColor="#FFFFFF"
android:layout_alignTop="#+id/textView_password"
android:layout_alignLeft="#id/textView_password"
android:layout_alignStart="#+id/editText_user" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Attempts :"
android:id="#+id/textView_attempt"
android:textColor="#FFFFFF"
android:paddingTop="40dp"
android:layout_centerVertical="true"
android:layout_alignRight="#+id/textView_username"
android:layout_alignEnd="#+id/textView_username" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textView_attempt_count"
android:layout_alignBottom="#+id/textView_attempt"
android:layout_alignLeft="#+id/editText_password"
android:layout_alignStart="#+id/editText_password"
android:textColor="#FFFFFF"/>
<Button
android:layout_width="160dp"
android:layout_height="40dp"
android:text="Login"
android:id="#+id/button_login"
android:background="#drawable/statelistdrawable"
android:textColor="#drawable/txco"
android:layout_above="#+id/textView_time"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/textView_time"
android:gravity="center"
android:textColor="#FFFFFF"
android:layout_above="#+id/button_FP"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="Forgot Password"
android:id="#+id/button_FP"
android:background="#android:color/transparent"
android:textColor="#drawable/tbutton"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
My Layout 1
Want to remove space between "Username" textview and "Name" edittext in Landscape. My layout is looking proper in portrait but gives space in between textview and edittext in landscape.

Android - Cannot allign two buttons in LinearLayout

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>

Aligning buttons at the button of the screen - Android

I am trying to align my buttons at the bottom of the screen using layouts but I cannot figure what's wrong with my code. I have tried several options by nesting different layouts but with no good outcome. it looks like this right now
And my code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout 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:id="#+id/relLayout"
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:clickable="true"
android:focusableInTouchMode="true"
tools:context="com.example.aurora.personalinformation.MainActivity">
<!-- Make the parent view clickable and focusable -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/title"
android:layout_centerHorizontal="true"
android:id="#+id/title"
android:textColor="#FF0000"
android:textSize="25dp"
android:textAlignment="center" />
<TextView
android:id="#+id/nameLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="15dp"
android:layout_marginTop="40dp"
android:layout_below="#id/title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText android:id="#+id/edit_name"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter name"
android:layout_alignBottom="#id/nameLable"
android:layout_toRightOf="#+id/phoneLable"
android:layout_toEndOf="#+id/phoneLable"
/>
<TextView
android:id="#+id/addressLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/address"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold"
android:layout_alignBottom="#+id/addressField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:id="#+id/addressField"
android:layout_weight="0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your address"
android:layout_below="#id/edit_name"
android:layout_alignLeft="#id/edit_name"
android:layout_alignStart="#id/edit_name" />
<TextView
android:id="#+id/phoneLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/phone"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="15dp"
android:layout_below="#id/addressField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp"/>
<EditText
android:id="#+id/phoneField"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your phone number"
android:layout_below="#id/addressField"
android:layout_toRightOf="#id/phoneLable"
android:layout_toEndOf="#id/phoneLable" />
<TextView
android:id="#+id/emailLable"
android:layout_below="#id/phoneLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold"
android:layout_marginTop="20dp"/>
<EditText
android:id="#+id/emailField"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your email"
android:layout_below="#id/phoneField"
android:layout_alignLeft="#id/phoneField"
android:layout_alignStart="#id/phoneField" />
<TextView
android:id="#+id/genderLable"
android:layout_below="#id/emailLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gender"
android:layout_marginTop="20dp"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="15dp" />
<Spinner
android:id="#+id/gender"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="#array/gender"
android:layout_alignTop="#+id/genderLable"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/emailField"
android:layout_alignStart="#+id/emailField" />
<TextView
android:id="#+id/country"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Country"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold"
android:layout_below="#id/gender"
android:layout_marginTop="15dp"/>
<AutoCompleteTextView
android:id="#+id/countryField"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your email"
android:layout_below="#id/gender"
android:layout_toRightOf="#id/phoneLable"
android:layout_toEndOf="#id/phoneLable" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
just give your last RelativeLayout like this:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_below="#+id/countryField"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:id="#+id/buttonCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
One more thing there is no meaning to give an orientation to RelativeLayout.

Unable to set header in Linear layout in android

<?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:background="#00b9e8"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:background="#ffffff" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Serch"
android:textColor="#000"
android:textSize="20sp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView2"
android:layout_marginRight="32dp"
android:src="#drawable/backbutton" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#6AED83"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Footer"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="122dp"
android:text="Enter Mobile Number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff"
android:textSize="20dp" />
<LinearLayout
android:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginLeft="14dp"
android:layout_marginTop="16dp"
android:background="#drawable/roundedlinearlayout3"
android:weightSum="4" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/user_s_icon" />
<EditText
android:id="#+id/editText1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter Mobile Number"
android:textColorHint="#0060a4" >
</EditText>
</LinearLayout>
<Button
android:id="#+id/signin"
android:layout_width="244dip"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/layout1"
android:layout_below="#+id/layout1"
android:layout_marginTop="27dp"
android:background="#drawable/rounded"
android:text="Search"
android:textColor="#ffffff"
android:textSize="10pt" />
</RelativeLayout>
This is my Xml i am Unable to set Linear layout inside text view and image button Like desire image:
This is my desire screen : below is my current screen :
i am unable to set text-view and image view on top of Linear layout
Try this way,hope this will help you to solve your problem.
Instead of using RelativeLayout use LinearLayout which can be easily done your requirement.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00b9e8"
android:orientation="vertical">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:gravity="center"
android:background="#ffffff" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Serch"
android:textColor="#000"
android:textSize="20sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/backbutton" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Mobile Number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff"
android:textSize="20dp" />
<LinearLayout
android:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="10dp"
android:background="#drawable/roundedlinearlayout3">
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Mobile Number"
android:textColorHint="#0060a4"
android:drawableLeft="#drawable/user_s_icon">
</EditText>
</LinearLayout>
<Button
android:id="#+id/signin"
android:layout_width="244dip"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/rounded"
android:text="Search"
android:textColor="#ffffff"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#6AED83"
android:gravity="center"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Footer"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>

Categories

Resources