When i placed my edit text into a linear layout to stop it from lagging is disappeared from the app screen and now my app crashes when its launched.(the ending of the code such as /linearLayout> is there it just wont show up on here)
old code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.trucktracker.MainActivity"
android:background="#drawable/background"
tools:ignore="MergeRootFrame">
<Button
android:id="#+id/continuebtn"
android:layout_width="match_parent"
android:layout_height="68dp"
android:layout_alignParentBottom="true"
android:onClick="clickedContinue"
android:text="#string/continue_btn"
android:textColor="#ffffff"
android:background="#drawable/btnbackreg"
android:layout_marginRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:textSize="30sp" />
<ImageView
android:id="#+id/legion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="262dp"
android:layout_marginRight="105dp"
android:contentDescription="#string/logo"
android:src="#drawable/legion" />
<TextView
android:id="#+id/question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/continuebtn"
android:layout_alignParentLeft="true"
android:layout_marginBottom="162dp"
android:text="#string/question1"
android:textSize="19sp"
android:textColor="#ffffff"
tools:context=".MainActivity" />
<EditText
android:id="#+id/Phonesignup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/continuebtn"
android:layout_alignParentLeft="true"
android:layout_marginBottom="65dp"
android:ems="10"
android:hint="#string/phonesignup"
android:inputType="phone"
android:textColorHint="#ffffff"
android:textColor="#ffffff"
android:textSize="20sp" >
</EditText>
<Spinner
android:id="#+id/optionselect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/Phonesignup"
android:layout_alignTop="#+id/question"
android:layout_marginBottom="45dp"
android:layout_marginLeft="18dp"
android:textColor="#b32017"
android:layout_toRightOf="#+id/question" />
new code:
<linearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/Phonesignup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="65dp"
android:ems="10"
android:hint="#string/phonesignup"
android:inputType="phone"
android:textColor="#ffffff"
android:textColorHint="#ffffff"
android:textSize="20sp" />
You typed the wrong tag for opening a LinearLayout. It should be a capital 'L', not a lowercase 'l'. Also, you need to set the orientation of a LinearLayout to either vertical or horizontal:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" (or horizontal)
>
Related
I am trying to develop a simple app for project management. The problem is with the xml layout of the app screens. The app screens are proportionally not very well put in different devices. Some elements are even hidden in some devices due to lack of space.
I already tried using both linear layout and relative layout. I've always used the "Match_parent" attribute to both the width and height of the relative layout and linear layout parent block. But still in some screen sizes, some elements are not showing, they are below the display area.
<RelativeLayout
android:id="#+id/layout1"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context=".login"
android:paddingTop="20dp"
>
<ImageView
android:id="#+id/loginImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/login_logo"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/loginText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="LOGIN"
android:textColor="#color/orange"
android:textSize="50sp"
android:layout_below="#id/loginImage"
/>
<EditText
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/logintextbackground"
android:layout_centerHorizontal="true"
android:layout_below="#id/loginText"
android:hint="Username"
android:textColorHint="#color/lightOrange"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="#color/lightOrange"
android:maxLength="15"
/>
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/logintextbackground"
android:layout_centerHorizontal="true"
android:layout_below="#id/username"
android:hint="Password"
android:textColorHint="#color/lightOrange"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="#color/lightOrange"
android:inputType="textPassword"
android:maxLength="16"
/>
<Button
android:id="#+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/login_button"
android:layout_below="#id/password"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="#+id/orText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="or"
android:textSize="20dp"
android:textColor="#color/orange"
android:layout_below="#id/loginButton"
android:layout_centerHorizontal="true"
/>
<Button
android:id="#+id/signUpButtonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/signup"
android:layout_below="#id/loginButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
/>
Put a ScrollView as parent of your RelativeLayout and you should be fine. Refer code below :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<RelativeLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:paddingTop="20dp"
tools:context=".login">
<ImageView
android:id="#+id/loginImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/login_logo" />
<TextView
android:id="#+id/loginText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loginImage"
android:layout_centerHorizontal="true"
android:text="LOGIN"
android:textColor="#color/orange"
android:textSize="50sp" />
<EditText
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loginText"
android:layout_centerHorizontal="true"
android:background="#drawable/logintextbackground"
android:hint="Username"
android:maxLength="15"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="#color/lightOrange"
android:textColorHint="#color/lightOrange" />
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/username"
android:layout_centerHorizontal="true"
android:background="#drawable/logintextbackground"
android:hint="Password"
android:inputType="textPassword"
android:maxLength="16"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:textColor="#color/lightOrange"
android:textColorHint="#color/lightOrange" />
<Button
android:id="#+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/password"
android:layout_centerHorizontal="true"
android:background="#drawable/login_button" />
<TextView
android:id="#+id/orText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loginButton"
android:layout_centerHorizontal="true"
android:text="or"
android:textColor="#color/orange"
android:textSize="20dp" />
<Button
android:id="#+id/signUpButtonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/loginButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="#drawable/signup" />
</RelativeLayout>
</ScrollView>
For future development, I would suggest you to use ConstraintLayout instead of LinearLayout or RelativeLayout as it provides less nesting of the views.
I am new all around design of UI inn android. and i have a 3 alignments problem in the follwoing image:
1. i would like that the rotatte laeft and right will be under the cent of the butoom "Select Photo".
2. for some reason the spinner near to the mobile edit text is not in the hegiht of the mobile edittext.
3.the "Create Account" buttom should be in the Bottom of the screen. but even when i add the following line:
android:layout_alignParentBottom="true"
nothing happend.
this is what i get in my device:
this is the xml code:
<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:orientation="vertical"
android:background="#ffffffff"
tools:context="com.example.matant.gpsportclient.Controllers.Register">
<RelativeLayout
android:layout_width="match_parent"
android:id="#+id/submainLayout"
android:layout_margin="10dp"
android:layout_height="match_parent">
<ImageView
android:src="#drawable/camera"
android:layout_width="120dp"
android:layout_height="120dp"
android:id="#+id/imageViewGallery"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:background="#drawable/border"
android:padding="1dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_alignParentStart="true" />
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow1"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/editTextName"
android:hint="Name"
android:background="#drawable/rounded_edit_text"
android:paddingLeft="10dp"
android:layout_marginTop="160dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow2"
android:layout_below="#+id/signupRow1"
android:layout_marginTop="5dp"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editTextEmail"
android:background="#drawable/rounded_edit_text"
android:padding="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Email"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow3"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow2"
android:layout_height="wrap_content">
<Spinner
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/spinnerMobile"
android:layout_marginRight="5dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:spinnerMode="dialog"
android:layout_marginBottom="5dp"
android:background="#606060"
android:layout_toLeftOf="#+id/buttonSelectImg"
android:layout_toStartOf="#+id/buttonSelectImg"
android:layout_below="#+id/editTextEmail"
android:layout_alignBottom="#+id/editTextMobile"
android:layout_weight="21.24" />
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:inputType="phone"
android:ems="10"
android:id="#+id/editTextMobile"
android:paddingLeft="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_edit_text"
android:hint="Mobile"
android:layout_weight="40.74" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow4"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow3"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:background="#drawable/rounded_edit_text"
android:id="#+id/editTextPassword"
android:paddingLeft="5dp"
android:hint="Password"
android:fontFamily="sans-serif"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow5"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow4"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:background="#drawable/rounded_edit_text"
android:id="#+id/editTextConfirmPass"
android:hint="Confirm Password"
android:paddingLeft="5dp"
android:fontFamily="sans-serif"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow6"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow5"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Gender:"
android:id="#+id/textViewGender"
android:layout_gravity="left|top"
android:layout_weight="5.18" />
<Spinner
android:layout_width="129dp"
android:layout_height="30dp"
android:id="#+id/spinnerGender"
android:background="#606060"
android:layout_weight="2.84" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow7"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow6"
android:layout_height="wrap_content"
android:baselineAligned="false">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Year of Birth:"
android:id="#+id/textViewyearOfBirth"
android:layout_weight="5.18" />
<Spinner
android:layout_width="129dp"
android:layout_height="30dp"
android:id="#+id/spinnerAge"
android:layout_marginLeft="10dp"
android:background="#606060"
android:layout_weight="3.14" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow8"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imageViewGallery"
android:layout_below="#+id/rotateLayout"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select Photo"
android:id="#+id/buttonSelectImg"
android:layout_marginTop="5dp"
android:background="#606060"
android:textColor="#ffffffff"
android:layout_marginLeft="5dp"
android:layout_margin="10dp"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow9"
android:layout_below="#+id/signupRow8"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/imageViewGallery">
</TableRow>
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="123dp"
android:background="#606060"
android:layout_marginLeft="5dp"
android:id="#+id/rotateLayout"
android:layout_toRightOf="#+id/imageViewGallery">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButtonRleftt"
android:background="#drawable/rotate_left"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButtonRright"
android:background="#drawable/rotate_right"
android:onClick="rottateRight"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<Button
android:id="#+id/ButtonSubmit"
android:text="Create Account"
android:layout_width="match_parent"
android:background="#606060"
android:textColor="#ffffffff"
android:layout_alignParentBottom="true"
android:layout_below="#+id/signupRow7"
android:layout_height="50dp"
android:layout_margin="5dp"
>
</Button>
</RelativeLayout>
Just set the width for both drawables to "wrap_content" and delete the weight attribute. Then add the gravity attribute to the table row like this:
<TableRow
android:layout_width="match_parent"
android:id="#+id/signupRow9"
android:layout_marginTop="5dp"
android:layout_below="#+id/signupRow8"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/imageViewGallery"
android:gravity="center">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButtonRleftt"
android:src="#drawable/rotate_right"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButtonRright"
android:src="#drawable/rotate_right"
android:onClick="rottateRight"/>
</TableRow>
The easiest way is to define a static height for you tablerow and then set the height attribute for your spinner and edittext to "match_parent". Another way is to get the height of your edittext programmatically and then set the height for the spinner at runtime. I would recommend the second method, because it looks better for different devices.
You're using the wrong attribute. Try it with android:layout_alignParentTop="true" to set the View to the top.
For the
1)use a single/separate table layout and add first row as "SELECT PHOTO" using colspan attribute and for the second row add the buttons using weight Attribute.
2)Instead of using warpcontent for both of them set layout_height="50dp" or anything, such that it's similar to other widgets in terms of height.
3)use CreateAccount widget directly without a tablerow with this attribute android:layout_alignParentTop="true" such that the parent of this widget is Relativelayout.
I have created an app in which there is an edittext to take input from user and below it there is an button. When the user click or focus on the edittext to input something the button position is changed by the keyboard and it overlap the edittext. I have tried the solution provided in
this answer. But it doesn't helped me
i have used this
android:windowSoftInputMode="stateVisible|adjustNothing
please someone hep....
Edit:
This is my layout xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#ffffff"
tools:context=".MyAds"
android:id="#+id/TestAd"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<EditText
android:id="#+id/edtLoanAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtLoanAmount"
android:layout_alignParentRight="true"
android:layout_below="#+id/txtLoanAmount"
android:ems="10"
android:background="#drawable/rounded_edittext_states"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/edtRateOfInterest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtRateOfInerest"
android:layout_alignParentRight="true"
android:layout_below="#+id/txtRateOfInerest"
android:ems="10"
android:background="#drawable/rounded_edittext_states"
android:inputType="numberDecimal" />
<TextView
android:id="#+id/txtRateOfInerest"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/edtLoanAmount"
android:layout_below="#+id/edtLoanAmount"
android:layout_marginTop="14dp"
android:text="Rate of Inerest"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtLoanAmount"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:text="Enter Loan Amount"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/txtLoanTenure"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/edtRateOfInterest"
android:layout_marginTop="16dp"
android:text="Loan Tenure (In Months)"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/edtLoanTenure"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/txtLoanTenure"
android:ems="10"
android:background="#drawable/rounded_edittext_states"
android:inputType="number" />
<TextView
android:id="#+id/txtEMI"
android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/btnCalculateEmi"
android:layout_marginTop="20dp"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnLoanAmorSchedule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txtEMI"
android:layout_marginTop="16dp"
android:background="#drawable/rounded_button_states"
android:text="Loan Amortization Schedule" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="125dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/initqube" />
<Button
android:id="#+id/btnCalculateEmi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingTop="3dp"
android:layout_marginTop="5dp"
android:layout_below="#id/edtLoanTenure"
android:background="#drawable/rounded_button_states"
android:text="Calculate EMI" />
<com.google.android.gms.ads.AdView
android:id="#+id/MyAdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/imageView1"
android:layout_alignParentLeft="true"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxx" >
</com.google.android.gms.ads.AdView>
</RelativeLayout>
</ScrollView>
my issue has been solved...
<Button
android:id="#+id/btnCalculateEmi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingTop="3dp"
android:layout_marginTop="5dp"
android:layout_below="#id/edtLoanTenure"
android:background="#drawable/rounded_button_states"
android:text="Calculate EMI" />
After removing the
android:layout_centerVertical="true"
from the button property. Everything works like a charm...
Add android:windowSoftInputMode="adjustPan"
in the Android Manifest XML file for your Activity.
In order to view all the elements inside my relativelayout in smaller screens, I have made the choice to use a scrollview to make it possible (or at least to try to accomplish this). The problem: I'm unable to scroll. The result of having or not the scrollview is the same, if the screen is small some elements will get cut off (this was fine if scroll was possible). In some searches I have come across some scrollview with linearlayout implementations, but in my case I think it's not very good, because i need check boxes aligned to the right of text.
Heres the xml of what I got thus far:
<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:background="#231E1A"
android:keepScreenOn="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"
tools:ignore="ContentDescription"
android:fillViewport="true">
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_getDirections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="#string/btn_getDirections" />
<TextView
android:id="#+id/static_language"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/radioGroup"
android:layout_alignLeft="#+id/radioGroup"
android:text="#string/static_language"
android:paddingTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<AutoCompleteTextView
android:id="#+id/aComplete_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/static_language"
android:layout_alignLeft="#+id/static_language"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_destination" />
<TextView
android:id="#+id/static_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/aComplete_destination"
android:layout_alignLeft="#+id/aComplete_destination"
android:text="#string/static_destination"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/static_highways"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_destination"
android:layout_alignLeft="#+id/static_destination"
android:paddingBottom="10dp"
android:text="#string/static_highways"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="#+id/static_tolls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_highways"
android:layout_alignLeft="#+id/static_highways"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/static_tolls"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="#+id/static_useCurrentLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_tolls"
android:layout_alignLeft="#+id/static_tolls"
android:paddingTop="10dp"
android:text="#string/static_useCurrentLocation"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<AutoCompleteTextView
android:id="#+id/aComplete_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/static_useCurrentLocation"
android:layout_alignLeft="#+id/static_useCurrentLocation"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_origin" >
<requestFocus />
</AutoCompleteTextView>
<TextView
android:id="#+id/static_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/aComplete_origin"
android:layout_alignLeft="#+id/aComplete_origin"
android:text="#string/static_origin"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_origin"
android:layout_alignLeft="#+id/static_origin"
android:layout_alignParentTop="true"
android:paddingBottom="10dp"
android:scaleType="fitStart"
android:src="#drawable/logo" />
<CheckBox
android:id="#+id/tolls_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_tolls"
android:layout_alignBottom="#+id/static_tolls"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/highways_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_highways"
android:layout_alignBottom="#+id/static_highways"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/useLocation_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_useCurrentLocation"
android:layout_alignBottom="#+id/static_useCurrentLocation"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btn_getDirections"
android:layout_alignLeft="#+id/btn_getDirections"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#FFFFFF"
android:layout_marginRight="20dp"
android:text="#string/radio_english" />
<RadioButton
android:id="#+id/radio_portugues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="#string/radio_portugues" />
</RadioGroup>
</RelativeLayout>
</ScrollView>
Huzzah! I got it to work! It was all a combination, of linearlayout, scrollview and relativelayout were was needed. Now it scrolls perfectly when the screen its not big enough to view the full content. I'm guessing that changing to linearlayout, was in fact the key in this. Basically i applied what was stated in developer site: http://developer.android.com/reference/android/widget/ScrollView.html
A child that is often used is a LinearLayout in a vertical
orientation, presenting a vertical array of top-level items that the
user can scroll through.
The xml:
<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:background="#231E1A"
android:keepScreenOn="true"
android:scrollbars="none"
android:overScrollMode="never"
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:ignore="ContentDescription"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:keepScreenOn="true"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/logo"
android:scaleType="fitStart"
android:src="#drawable/logo"/>
<TextView
android:id="#+id/static_origin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/static_origin"
android:paddingTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<AutoCompleteTextView
android:id="#+id/aComplete_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_origin" >
<requestFocus />
</AutoCompleteTextView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/static_useCurrentLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:paddingTop="10dp"
android:text="#string/static_useCurrentLocation" />
<TextView
android:id="#+id/static_tolls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/static_useCurrentLocation"
android:layout_below="#+id/static_useCurrentLocation"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/static_tolls" />
<TextView
android:id="#+id/static_highways"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/static_tolls"
android:layout_alignLeft="#+id/static_tolls"
android:paddingBottom="10dp"
android:text="#string/static_highways"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<CheckBox
android:id="#+id/tolls_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_tolls"
android:layout_alignBottom="#+id/static_tolls"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/highways_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_highways"
android:layout_alignBottom="#+id/static_highways"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/useLocation_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_useCurrentLocation"
android:layout_alignBottom="#+id/static_useCurrentLocation"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
</RelativeLayout>
<TextView
android:id="#+id/static_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/static_destination"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
<AutoCompleteTextView
android:id="#+id/aComplete_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_destination" />
<TextView
android:id="#+id/static_language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/static_language"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#FFFFFF"
android:layout_marginRight="20dp"
android:text="#string/radio_english" />
<RadioButton
android:id="#+id/radio_portugues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="#string/radio_portugues" />
</RadioGroup>
<Button
android:id="#+id/btn_getDirections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/btn_getDirections" />
</LinearLayout>
</ScrollView>
I have TextView in RelativeLayout, which works properly:
<TextView
android:id="#+id/tv_client_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tv_label_client_out"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_in"
android:background="#drawable/border"
android:ems="10" />
Now I need to place this TextView inside of ScrollView:
<ScrollView android:id="#+id/sv_client_in"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tv_label_client_out"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_in"
android:background="#drawable/border"
android:fillViewport="true"
>
<TextView
android:id="#+id/tv_client_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
/>
</ScrollView>
After this change layout looks OK (first image), but when keyboard is shown, it is corrupted (second image). How can I fix this?
Full layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tv_label_client_host"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:ems="10"
android:text="#string/label_host" />
<EditText
android:id="#+id/et_client_host"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_host"
android:ems="10"
android:inputType="text"
android:lines="1" />
<TextView
android:id="#+id/tv_label_client_port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/et_client_host"
android:ems="10"
android:text="#string/label_port" />
<EditText
android:id="#+id/et_client_port"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_port"
android:ems="10"
android:inputType="number"
android:lines="1" />
<ScrollView android:id="#+id/sv_client_in"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/tv_label_client_out"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/tv_label_client_in"
android:background="#drawable/border"
android:fillViewport="true"
>
<TextView
android:id="#+id/tv_client_in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
/>
</ScrollView>
<Button
android:id="#+id/btn_client_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/btn_send"
android:onClick="OnBtnSendClick"
/>
<TextView
android:id="#+id/tv_label_client_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btn_client_send"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:ems="10"
android:text="#string/label_client_out" />
<EditText
android:id="#+id/et_client_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/btn_client_send"
android:ems="10"
android:inputType="text"
android:lines="1" />
<Button
android:id="#+id/btn_client_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/et_client_port"
android:text="#string/btn_client_clear"
android:onClick="OnBtnClearClick"
/>
<Button
android:id="#+id/btn_client_disconnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/et_client_port"
android:text="#string/btn_client_disconnect"
android:onClick="OnBtnDisconnectClick"
/>
<Button
android:id="#+id/btn_client_connect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_client_port"
android:layout_toLeftOf="#+id/btn_client_disconnect"
android:text="#string/btn_client_connect"
android:onClick="OnBtnConnectClick"
/>
<TextView
android:id="#+id/tv_label_client_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/btn_client_connect"
android:ems="10"
android:text="#string/label_client_in"
/>
</RelativeLayout>
This happens mainly because of the views aligning to bottom. You have aligned them to bottom, so when the keyboard pops up the bottom changes hence the Views associated with it.
Try checking your xml file.
The problem is solved by using LinearLayout.