Why does my send button keep overlapping my edit text? - android

I have a scrollview with a relative layout inside of it. When I have the relative layout height set to match_parent it does this to the graphical layout and I do not know why it's doing this. ---PICTURE BELOW---
Here is the activity_main.xml file:
<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"
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=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText
android:id="#+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:ems="10"
android:hint="First and Last Name"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/etName"
android:layout_marginTop="14dp"
android:ems="10"
android:hint="Enter Phone #"
android:inputType="phone" />
<EditText
android:id="#+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/etPhone"
android:layout_marginTop="17dp"
android:ems="10"
android:hint="Enter E-mail"
android:inputType="textEmailAddress" />
<EditText
android:id="#+id/etAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/etEmail"
android:layout_marginTop="18dp"
android:ems="10"
android:hint="Additional Information"
android:lines="5"
android:inputType="textMultiLine" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/etPhone"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Contact Form"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/send"
android:layout_width="match_parent"
android:layout_height="125dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Send" />
</RelativeLayout>
</ScrollView>
I have also tried to set the scroll view width and height to fill_parent and it still does the same thing. What am I doing wrong?
Thank you in advance!

You haven't specified the correct positioning of Button
Add android:layout_below="#+id/etAdd" to your button
<Button
android:id="#+id/send"
android:layout_width="match_parent"
android:layout_height="125dp"
android:layout_below="#+id/etAdd"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Send" />

Try this,
<Button
android:id="#+id/send"
android:layout_width="match_parent"
android:layout_height="125dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="#+id/yourEdt"
android:text="Send" />

Related

ScrollView Open my edittexts and work only if open

i have a bad problem. i need to use a scrollview into my app, but this on start open editext Keyboard.
If Keyboard is open, scrollview work, but if i close the keybord scroll not work.
How to resolve this ploblem?
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/taglio"
android:orientation="horizontal"
android:layout_weight="1">
<Button
android:text="+"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/piutagliodonna"
android:textStyle="normal|bold"
android:layout_weight="1"
android:alpha="0.70"
/>
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/editTexttagliodonna"
android:hint="0"
android:textAlignment="center"
android:layout_weight="1"/>
<Button
android:text="-"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/menotagliodonna"
android:layout_weight="1"
android:textStyle="normal|bold"
android:alpha="0.70"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Try this, but change and add RelativeLayout to LinearLayout:
<?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="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="pl.com.qubuss.test.RegisterActivity">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/nameET"
android:layout_marginTop="20dp"
android:inputType="textPersonName"
android:hint="#string/nameTextHint"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:width="200dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/surnameET"
android:layout_below="#+id/nameET"
android:layout_alignLeft="#+id/nameET"
android:layout_alignStart="#+id/nameET"
android:layout_marginTop="20dp"
android:width="200dp"
android:hint="#string/surnameTextHint" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/emailET"
android:hint="#string/emailTextHint"
android:width="200dp"
android:layout_below="#+id/surnameET"
android:layout_alignLeft="#+id/surnameET"
android:layout_alignStart="#+id/surnameET"
android:layout_marginTop="20dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/username_registerET"
android:layout_below="#+id/emailET"
android:layout_alignLeft="#+id/emailET"
android:layout_alignStart="#+id/emailET"
android:layout_marginTop="20dp"
android:width="200dp"
android:hint="#string/usernameTextHint" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/password_registerET"
android:layout_below="#+id/username_registerET"
android:layout_alignLeft="#+id/username_registerET"
android:layout_alignStart="#+id/username_registerET"
android:layout_marginTop="20dp"
android:hint="#string/passwordTextHint" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/registerButton"
android:id="#+id/registerButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="23dp"
android:layout_below="#+id/conPasswor_registerET"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/conPasswor_registerET"
android:layout_marginTop="20dp"
android:layout_below="#+id/password_registerET"
android:layout_alignLeft="#+id/password_registerET"
android:layout_alignStart="#+id/password_registerET"
android:hint="#string/conPasswordTextHint" />
</RelativeLayout>
</ScrollView>

RelativeLayout does not expand with the heights of view elements

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.

How to position an included layout on the bottom of the original layout in android?

I am having problem laying out my included layout directly below the parent layout.
The original layout of the activity is a Relative Layout, I nested it under a Linear layout followd by the
<include layout="#layout/activity_passport_search"/>
but they end up covering each other.
Below is the full layout .xml I am using
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="12dip">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" 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"
app:layout_behavior="#string/appbar_scrolling_view_behavior" tools:showIn="#layout/app_bar_main"
tools:context=".MainActivity"
android:elevation=".5dp"
android:background="#drawable/bg"
android:focusable="true">
<ImageView
android:id="#+id/imgLogo"
android:layout_width="250dp"
android:layout_height="150dp"
android:src="#drawable/h_biglogo"
android:paddingTop="8.5dp"
android:paddingBottom="8.5dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/hiaTextField"
android:layout_alignEnd="#+id/hiaTextField"
android:layout_above="#+id/hiaTextField" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/hiaTextField"
android:selectAllOnFocus="true"
android:hint="UserName"
android:drawableLeft="#android:drawable/ic_dialog_email"
android:text="historya"
android:autoText="false"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dip"
android:background="#AA000000"
android:textColor="#ffffffff"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/hiaPassword"
android:hint="Password"
android:drawableLeft="#android:drawable/ic_lock_idle_lock"
android:text="password"
android:layout_gravity="center_horizontal|bottom"
android:padding="12dip"
android:background="#AA000000"
android:textColor="#ffffffff"
android:layout_alignParentEnd="true"
android:layout_below="#+id/hiaTextField"
android:layout_alignParentRight="true" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
android:id="#+id/hiaButton"
android:onClick="hiaSubmitClick"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_below="#+id/hiaPassword"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="18sp"
android:textColor="#color/colorWhite"
android:alpha="20"
android:layout_alignRight="#+id/hiaPassword"
android:layout_alignEnd="#+id/hiaPassword" />
<Button
android:id="#+id/fbButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Login using Facebook"
android:drawableLeft="#drawable/fb_white"
android:layout_centerHorizontal="true"
android:layout_below="#+id/hiaButton"
android:textSize="18sp"
android:alpha="20"
style="#style/Widget.AppCompat.Button.Colored"
android:onClick="hiaFbLogin" />
</RelativeLayout>
<include layout="#layout/activity_passport_search"/>
</LinearLayout>
Change the width and height of the parent LinearLayout as match_parent and match_parent respectively.
And for the relative layout change the height and width to wrap_content and match_parent respectively.
Other alternative you have is :
Remove the parent LinearLayout and for the layout you are including make the following changes :
<include android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom = "true"
android:layout_below="#id/fbButton"
layout="#layout/activity_passport_search"/>
You have to create this like below:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="12dip">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:elevation=".5dp"
android:focusable="true"
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"
>
<ImageView
android:id="#+id/imgLogo"
android:layout_width="250dp"
android:layout_height="150dp"
android:layout_above="#+id/hiaTextField"
android:layout_alignEnd="#+id/hiaTextField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/hiaTextField"
android:paddingBottom="8.5dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="8.5dp"
android:src="#drawable/ic_launcher" />
<EditText
android:id="#+id/hiaTextField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal|bottom"
android:autoText="false"
android:background="#AA000000"
android:drawableLeft="#android:drawable/ic_dialog_email"
android:hint="UserName"
android:padding="12dip"
android:selectAllOnFocus="true"
android:text="historya"
android:textColor="#ffffffff" />
<EditText
android:id="#+id/hiaPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/hiaTextField"
android:layout_gravity="center_horizontal|bottom"
android:background="#AA000000"
android:drawableLeft="#android:drawable/ic_lock_idle_lock"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:padding="12dip"
android:text="password"
android:textColor="#ffffffff" />
<Button
android:id="#+id/hiaButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/hiaPassword"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/hiaPassword"
android:layout_below="#+id/hiaPassword"
android:alpha="20"
android:onClick="hiaSubmitClick"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="LOGIN"
android:textColor="#android:color/white"
android:textSize="18sp" />
<Button
android:id="#+id/fbButton"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/hiaButton"
android:layout_centerHorizontal="true"
android:alpha="20"
android:drawableLeft="#drawable/ic_launcher"
android:onClick="hiaFbLogin"
android:text="Login using Facebook"
android:textSize="18sp" />
</RelativeLayout>
<include layout="#layout/activity_passport_search" />
</LinearLayout>
For making the layout as you wish, you need to make your parent layout from LinearLayout to RelativeLayout and make it's width & height to match_parent.
The complete layout is below,
<?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:padding="12dip">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/include_passport_bottom"
android:background="#drawable/bg"
android:elevation=".5dp"
android:focusable="true"
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=".MainActivity">
<ImageView
android:id="#+id/imgLogo"
android:layout_width="250dp"
android:layout_height="150dp"
android:layout_above="#+id/hiaTextField"
android:layout_alignEnd="#+id/hiaTextField"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/hiaTextField"
android:paddingBottom="8.5dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="8.5dp"
android:src="#drawable/h_biglogo" />
<EditText
android:id="#+id/hiaTextField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal|bottom"
android:autoText="false"
android:background="#AA000000"
android:drawableLeft="#android:drawable/ic_dialog_email"
android:hint="UserName"
android:padding="12dip"
android:selectAllOnFocus="true"
android:text="historya"
android:textColor="#ffffffff" />
<EditText
android:id="#+id/hiaPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/hiaTextField"
android:layout_gravity="center_horizontal|bottom"
android:background="#AA000000"
android:drawableLeft="#android:drawable/ic_lock_idle_lock"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:padding="12dip"
android:text="password"
android:textColor="#ffffffff" />
<Button
android:id="#+id/hiaButton"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/hiaPassword"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/hiaPassword"
android:layout_below="#+id/hiaPassword"
android:alpha="20"
android:onClick="hiaSubmitClick"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="LOGIN"
android:textColor="#color/colorWhite"
android:textSize="18sp" />
<Button
android:id="#+id/fbButton"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/hiaButton"
android:layout_centerHorizontal="true"
android:alpha="20"
android:drawableLeft="#drawable/fb_white"
android:onClick="hiaFbLogin"
android:text="Login using Facebook"
android:textSize="18sp" />
</RelativeLayout>
<include
android:id="#+id/include_passport_bottom"
layout="#layout/activity_passport_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

EditText and Textview not displayed in layout

Hey StackOverflow community.
I am working on an android app right now and I got some problem with the layout of a fragment.
My problem is that the textviews and edittexts are not displayed, they are like squeeze in the layout design mode of android studio. It's the same thing when I run the app in the emulator. I am using a relativeLayout and the gravity is set to bottom.
I have tried different thing like changing the gravity, the layout height for the relativeLayout and the textView/editText but nothing work.
Here is the XML
<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="com.project.vincent.activityplanner.InfoPanelActivity"
android:gravity="bottom">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="#color/white"
android:layout_above="#+id/textView3"
android:text="test" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="#color/white"
android:layout_alignParentStart="true"
android:layout_above="#+id/dateStart"
android:text="test" />
<TextView
android:id="#+id/textView4"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="#color/white"
android:layout_alignParentStart="true"
android:layout_above="#+id/dateStart"
android:layout_alignBottom="#+id/dateStart"
android:text="Start" />
<EditText
android:id="#+id/dateStart"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:layout_toStartOf="#+id/timeStart"
android:layout_alignBottom="#+id/timeStart" />
<EditText
android:id="#+id/timeStart"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:layout_above="#+id/timeEnd"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/textView5"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="#color/white"
android:layout_alignParentStart="true"
android:layout_above="#+id/dateEnd"
android:text="Start" />
<EditText
android:id="#+id/dateEnd"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:layout_toStartOf="#+id/timeEnd"
android:layout_alignBottom="#id/timeEnd"/>
<EditText
android:id="#+id/timeEnd"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:layout_above="#+id/ratingBar"
android:layout_alignParentEnd="true" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save" />
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Only the save button and the rating bar are displayed correctly.
Layout Result
Layout Expectation
If you have an idea on how to solve this problem I would really appreciate your help.
Thanks
<?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="com.project.vincent.activityplanner.InfoPanelActivity"
android:gravity="bottom">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_above="#+id/textView3"
android:text="test2" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_alignParentStart="true"
android:layout_above="#+id/dateStart"
android:text="test3" />
<TextView
android:id="#+id/textView4"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_alignParentStart="true"
android:layout_above="#+id/dateStart"
android:layout_alignBottom="#+id/dateStart"
android:text="Start" />
<EditText
android:id="#+id/dateStart"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:layout_toStartOf="#+id/timeStart"
android:layout_alignBottom="#+id/timeStart" />
<EditText
android:id="#+id/timeStart"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:layout_above="#+id/timeEnd"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/textView5"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:visibility="visible"
android:text="End"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/dateEnd"
android:layout_above="#+id/ratingBar"/>
<EditText
android:id="#+id/dateEnd"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:layout_toStartOf="#+id/timeEnd"
android:layout_alignBottom="#id/timeEnd"/>
<EditText
android:id="#+id/timeEnd"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:layout_above="#+id/ratingBar"
android:layout_alignParentEnd="true" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"/>
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
RelativeLayout allows you to place elements "one after another".
use "layoutAlignComponent" section of your elements in desisgner to stick them to each other.
I can see you already tried with your android:id="#+id/textView2" as it has android:layout_above="#+id/textView3" field.
Firstly you have to remove the android:gravity="bottom" property from the parent relative layout then you have to add the following code to show your save button and rating bar in bottom
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save" />
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
and then you have to remove the white color property from the textviews and then after that you can see your textviews and align them as per your UI.
Change your parent layout in linear layout.Because RelativeLayout is a view
group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
Your screen look likethat after changing parent to linear.
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.project.vincent.activityplanner.InfoPanelActivity"
android:gravity="bottom">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="#color/white"
android:layout_above="#+id/textView3"
android:text="test" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="#color/white"
android:layout_alignParentStart="true"
android:layout_above="#+id/dateStart"
android:text="test" />
<TextView
android:id="#+id/textView4"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="#color/white"
android:layout_alignParentStart="true"
android:layout_above="#+id/dateStart"
android:layout_alignBottom="#+id/dateStart"
android:text="Start" />
<EditText
android:id="#+id/dateStart"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:layout_toStartOf="#+id/timeStart"
android:layout_alignBottom="#+id/timeStart" />
<EditText
android:id="#+id/timeStart"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:layout_above="#+id/timeEnd"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/textView5"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:visibility="visible"
android:background="#color/white"
android:layout_alignParentStart="true"
android:layout_above="#+id/dateEnd"
android:text="Start" />
<EditText
android:id="#+id/dateEnd"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:layout_toStartOf="#+id/timeEnd"
android:layout_alignBottom="#id/timeEnd"/>
<EditText
android:id="#+id/timeEnd"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:layout_above="#+id/ratingBar"
android:layout_alignParentEnd="true" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save" />
<RatingBar
android:id="#+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true" />

Android:how to center individual views when layout's gravity is fixed

I am using Linear Layout for this 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:gravity="center"
>
<EditText
android:id="#+id/editTextUserNameToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="User Name">
<requestFocus />
</EditText>
<EditText
android:id="#+id/editTextPasswordToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="#+id/buttonSignIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sign In" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New ToggleButton"
android:id="#+id/toggleButton"/>
</LinearLayout>
I want all text views to appear in the center of the screen,
except for the the toggle button which i want it to be in the right-bottom of the screen.
As you can see, i am using android:gravity center in the layout's tag, because neither this nor android:layout_gravity was working on individual textviews.
But now i want toggle button to be independent of this.
How can i achieve it?
test this xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center"
android:orientation="vertical" >
<EditText
android:id="#+id/editTextUserNameToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="User Name" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editTextPasswordToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="#+id/buttonSignIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sign In" />
</LinearLayout>
<ToggleButton
android:id="#+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New ToggleButton" />
Just wrap the entire layout into a FrameLayout and keep the toggle button outside of the LinearLayout. then put layout_gravity as you wish. Thats the trick. cheers :)
Try this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
>
<EditText
android:id="#+id/editTextUserNameToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="User Name">
<requestFocus />
</EditText>
<EditText
android:id="#+id/editTextPasswordToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="#+id/buttonSignIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Sign In" />
</LinearLayout>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New ToggleButton"
android:layout_gravity="bottom|right"
android:id="#+id/toggleButton"/>
</FrameLayout>
You can use relative layout look this code how you can set your xml as per your requirement.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editTextUserNameToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_centerInParent="true"
android:hint="User Name">
<requestFocus />
</EditText>
<EditText
android:id="#+id/editTextPasswordToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:layout_below="#+id/editTextUserNameToLogin"
android:inputType="textPassword" />
<Button
android:id="#+id/buttonSignIn"
android:layout_width="fill_parent"
android:layout_below="#+id/editTextPasswordToLogin"
android:layout_height="wrap_content"
android:text="Sign In" />
<ToggleButton
android:id="#+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="New ToggleButton" />
</RelativeLayout>
This is it what you want.
Thanks
check this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editTextUserNameToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_centerInParent="true"
android:hint="User Name">
<requestFocus />
</EditText>
<EditText
android:id="#+id/editTextPasswordToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:layout_below="#+id/editTextUserNameToLogin"
android:inputType="textPassword" />
<Button
android:id="#+id/buttonSignIn"
android:layout_width="fill_parent"
android:layout_below="#+id/editTextPasswordToLogin"
android:layout_height="wrap_content"
android:text="Sign In" />
<ToggleButton
android:id="#+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="New ToggleButton" />
</RelativeLayout>

Categories

Resources