The following file is intended to allow full vertical scrolling in Android devices.
However when opening the app in Android Studio the light blue rectangular box ends just before where the buttons begin. Does not scroll. Members of Stack Overflow have helped me to overcome the file not opening. I thank them. But issue of scrolling remains.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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="com.cancunsteve.aboutcancunsteve.MainActivity"
tools:showIn="#layout/activity_main">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/scrollView"
android:layout_alignParentStart="true"
android:layout_marginTop="56dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView android:id="#+id/imageView"
android:layout_column="1"
android:background="#mipmap/lpussy"
android:contentDescription='android:ContentDescription="#string/desc"'
tools:ignore="HardcodedText"
android:layout_width="200dp"
android:layout_height="230dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" We've been ... "
android:id="#+id/text1"
android:layout_alignTop="#+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#ffffff"
android:foreground="#05ffffff"
android:foregroundTint="#03ffffff"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:text="Cancun, Playa del Carmen, ..."
android:layout_below="#+id/text1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:text="Holbox, ..."
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#mipmap/campa"
tools:ignore="ContentDescription"
android:layout_alignBottom="#+id/editText5" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText3"
android:text="thewebmaster#cancunsteve.com"
android:layout_below="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/editText4"
android:text=" 011 52 998 8873919"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="42dp"
android:layout_marginStart="32dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText5"
android:text="be sure ..."
android:layout_below="#+id/editText4"
android:layout_toRightOf="#+id/ScrollView"
android:layout_toEndOf="#+id/ScrollView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click buttons multiple times to change state"
android:id="#+id/textView2"
android:layout_below="#+id/imageButton" />
</RelativeLayout>
</ScrollView>
Related
The content_mail.xml file will not open. I am attempting to produce a ScrollView for the entire android screen for all views within. Code follows this is a revision of prior code posted:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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="com.cancunsteve.aboutcancunsteve.MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_alignParentStart="true"
android:layout_marginTop="56dp" />
<ImageView android:id="#+id/imageView"
android:layout_column="1"
android:background="#mipmap/lpussy"
android:contentDescription='android:ContentDescription="#string/desc"'
tools:ignore="HardcodedText"
android:layout_width="200dp"
android:layout_height="230dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" We've been serving good people like you since 1994 with special deals on their travel plans. "
android:id="#+id/text1"
android:layout_alignTop="#+id/imageView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#ffffff"
android:foreground="#05ffffff"
android:foregroundTint="#03ffffff"
android:textColor="#000000" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:text="Cancun, Chichen Itza."
android:layout_below="#+id/text1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:text="Holbox, Taxco, Palenque, Acapulco, Ixtapa, Guanajuato,
Cabo San Lucas, Puerto Vallarta, Monterrey, Tenacatita, Mascota"
android:layout_below="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#mipmap/campa"
tools:ignore="ContentDescription"
android:layout_alignBottom="#+id/editText5" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editText3"
android:text="thewebmaster#cancunsteve.com"
android:layout_below="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/editText"
android:layout_alignEnd="#+id/editText" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/editText4"
android:text=" 011 52 998 8873919"
android:layout_below="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="42dp"
android:layout_marginStart="32dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText5"
android:text="be sure to visit us discounts on your hotel bookings"
android:layout_below="#+id/editText4"
android:layout_toRightOf="#+id/scrollView"
android:layout_toEndOf="#+id/scrollView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click buttons multiple times to change state"
android:id="#+id/textView2"
android:layout_below="#+id/imageButton" />
</RelativeLayout>
</ScrollView>
The above code incorporates changes suggested as I understood them or misunderstood them. One suggestion was to remove the images. But I require them.
Remove tools:showIn="#layout/activity_main" and replace the code with below code and also replace cloasing tag </RelativeLayout> with </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginTop="56dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="200dp"
android:layout_height="230dp"
android:layout_column="1"
android:background="#mipmap/ic_launcher"
android:contentDescription='android:ContentDescription="#string/desc"'
tools:ignore="HardcodedText" />
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView"
android:background="#ffffff"
android:foreground="#05ffffff"
android:foregroundTint="#03ffffff"
android:text="We've been serving good people like you since 1994 with special deals on their travel plans. "
android:textColor="#000000" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/text1"
android:text="Cancun, Chichen Itza." />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText2"
android:text="Holbox, Taxco, Palenque, Acapulco, Ixtapa, Guanajuato,
Cabo San Lucas, Puerto Vallarta, Monterrey, Tenacatita, Mascota" />
<ImageButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText3"
android:background="#mipmap/ic_launcher"
tools:ignore="ContentDescription" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/editText"
android:layout_below="#+id/editText"
android:ems="10"
android:inputType="textEmailAddress"
android:text="thewebmaster#cancunsteve.com" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText3"
android:layout_marginLeft="42dp"
android:layout_marginStart="32dp"
android:ems="10"
android:inputType="phone"
android:text="011 52 998 8873919" />
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText4"
android:text="be sure to visit us discounts on your hotel bookings" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageButton"
android:text="click buttons multiple times to change state" />
</LinearLayout>
</ScrollView>
Every time I add widgets or stuff, below exception always occurs, so I can't even run my project. What causes this problem? What is the solution? I'm very new to Android Studio, and I hope you guys will help me. Every answer of you will be my pleasure. Thanks!
Here is my Layout.xml
<?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:id="#+id/activity_main"
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.example.leeroyld.testproject.MainActivity">
<Button
android:text="#string/LoginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_marginBottom="79dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#android:color/background_dark"
android:backgroundTint="#android:drawable/bottom_bar"
android:textColor="#android:color/background_light" />
<TextView
android:text="#string/LoginLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/EmailDisplay"
android:textSize="24sp"
android:layout_below="#+id/textView"
android:layout_alignParentStart="true"
android:layout_marginTop="36dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/PasswordInput"
tools:ignore="LabelFor"
android:layout_marginBottom="42dp"
android:layout_above="#+id/button"
android:layout_centerHorizontal="true"
android:background="?attr/actionModeBackground" />
<TextView
android:text="#string/PasswordLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/PasswordDisplay"
android:textSize="24sp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
<TextView
android:text="#string/TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:textSize="24sp"
android:layout_marginTop="31dp"
android:background="#android:drawable/button_onoff_indicator_on"
android:backgroundTint="#android:drawable/alert_light_frame"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/EmailInput"
tools:ignore="LabelFor"
android:layout_marginTop="24dp"
android:background="?attr/actionModeBackground"
android:layout_below="#+id/EmailDisplay"
android:layout_alignStart="#+id/PasswordInput" />
</RelativeLayout>
Remove the android:backgroundTint from LoginButton and TextView. Your final layout should look like this.
<?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:id="#+id/activity_main"
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">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="79dp"
android:background="#android:color/background_dark"
android:text="Login"
android:textColor="#android:color/background_light" />
<TextView
android:id="#+id/EmailDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_marginTop="36dp"
android:text="Email"
android:textSize="24sp" />
<EditText
android:id="#+id/PasswordInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="42dp"
android:background="?attr/actionModeBackground"
android:ems="10"
android:inputType="textPassword"
tools:ignore="LabelFor" />
<TextView
android:id="#+id/PasswordDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Password"
android:textSize="24sp" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp"
android:background="#android:drawable/button_onoff_indicator_on"
android:text="TextView"
android:textSize="24sp" />
<EditText
android:id="#+id/EmailInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/EmailDisplay"
android:layout_marginTop="24dp"
android:background="?attr/actionModeBackground"
android:ems="10"
android:inputType="textEmailAddress"
tools:ignore="LabelFor" />
</RelativeLayout>
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.
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" />
My XML Preview design before executing android studio.
After Executing android studio design is showing old design, I changed EditText name but still showing the same name and also added new button that also not reflecting after run my android app.
Below is my XML design:
<?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="com.cnkonline.demo2.MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Email"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="55dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Password"
android:id="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_alignParentStart="true"
android:layout_marginTop="42dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Mobile"
android:id="#+id/textView3"
android:layout_below="#+id/textView2"
android:layout_alignParentStart="true"
android:layout_marginTop="42dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="#+id/button"
android:layout_toEndOf="#+id/textView2"
android:layout_marginTop="77dp"
android:layout_alignTop="#+id/textView3" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_gravity="center"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_gravity="center"
android:layout_below="#+id/textView2"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText3"
android:layout_gravity="center"
android:layout_below="#+id/textView3"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/button2"
android:layout_below="#+id/button"
android:layout_alignEnd="#+id/button" />