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>
Related
I have an EditText on the bottom of my layout und a few TextViews on the top. When I click on the EditText it moves from the bottom above the keyboard which is good. But the TextViews also move up and out of the screen so you can't see them until you close the keyboard again. How can I avoid this but still have my EditText above the keyboard? I'm using a RelativeLayout.
Thanks!
<?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: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.ncss.tyfby.Feeling"
android:background="#1baa84">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:text="I am"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/IamTV"
android:layout_weight="0.10"
android:textSize="40sp"
android:textStyle="normal|bold"
android:gravity="bottom" />
<EditText
android:layout_width="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/iamAdjective"
android:background="#android:drawable/editbox_background_normal"
android:hint="powerful"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/send"
android:layout_weight="0.10"
android:src="#android:drawable/ic_menu_send"
android:background="#drawable/transparent"
android:onClick="send"
android:layout_marginLeft="5dp" />
</LinearLayout>
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam1"
android:textSize="18sp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam2"
android:textSize="18sp"
android:layout_below="#+id/iam1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam4"
android:textSize="18sp"
android:layout_below="#+id/iam3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam5"
android:textSize="18sp"
android:layout_below="#+id/iam4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam3"
android:textSize="18sp"
android:layout_below="#+id/iam2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
You may explore windowSoftInputMode that you can configure for your Activity in the AndroidManifest.xml file: activity | Android Developers.
Perhaps windowSoftInputMode="adjustResize" might be useful for you.
In addition to that you will need to change your layout XML to something like:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context="com.ncss.tyfby.Feeling"
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"
android:background="#1baa84">
<ScrollView
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_weight="1">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam1"
android:textSize="18sp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam2"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam4"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam5"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:text="I am"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iam3"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:text="I am"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/IamTV"
android:layout_weight="0.10"
android:textSize="40sp"
android:textStyle="normal|bold"
android:gravity="bottom" />
<EditText
android:layout_width="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/iamAdjective"
android:background="#android:drawable/editbox_background_normal"
android:hint="powerful"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/send"
android:layout_weight="0.10"
android:src="#android:drawable/ic_menu_send"
android:background="#drawable/transparent"
android:onClick="send"
android:layout_marginLeft="5dp" />
</LinearLayout>
</LinearLayout>
You should put your entire layout inside a ScrollView and force that to be above of my_edit_text:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/my_edit_text">
Hi in the below code i have these layout. once touch inside username edittext i want to move full layout upwards.onfousing the keyboard should be stay like that want to move full layout upwards
Can any one help me
layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#drawable/texture">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFFFFF"
android:orientation="vertical"
android:id="#+id/login">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:paddingTop="100dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#6E6864"
android:text="Sign in to continue"
android:id="#+id/login_tv_sign_continue" />
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:paddingLeft="10dp"
android:hint="User Name"
android:id="#+id/login_ed_username"
android:background="#drawable/edit_text_back"
android:imeOptions="actionNext"
android:singleLine="true"
/>
<EditText
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:paddingLeft="10dp"
android:hint="Password"
android:id="#+id/login_ed_password"
android:background="#drawable/edit_text_back"
android:imeOptions="actionDone"
android:singleLine="true"
android:inputType="textPassword"
/>
<Button
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:textColor="#6E6864"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/login_btn_login"
android:text="Sign In"
android:background="#ECBC3B"
/>
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/txt_forgetpwd"
android:text="Forgot Password?"
android:gravity="right"
android:layout_marginTop="20dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/logo"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
I'm a beginner in android. I'm creating a example phonebook using eclipse. i have few edit texts and a set off buttons in my layout.but when I run the project I can't see the buttons in the bottom of the layout, so I enclosed my main linear layout in a Scrollview. but after linear layout has become much bigger in height. i tried to resize it in the xml file but it is not working right after resizing the layout it automatically resizes in to the previous size. here's my code if anyone can help me.little help is highly appreciated.
<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="466dp"
android:layout_gravity="center_vertical" >
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/back"
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:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical"
tools:context="com.nadusha.phonebook.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Info"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/nameTextLayout"
android:orientation="horizontal"
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<requestFocus />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"/>
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/mobileNoTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/homeNoTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-Mail "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/emailTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/saveBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:textColor="#FFFFFF"/>
<Button
android:id="#+id/cancelBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/viewBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ViewContact"
android:textColor="#FFFFFF" />
</Linearlayout>
</LinearLayout>
You need to set ScrollView layoutWeight to 1 and its height to 0. This will ensure that your scrollview will take only remaining space on screen. Here is example of my app:
<?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:orientation="vertical"
>
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clickable="false"
android:fadeScrollbars="false"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="#+id/menoLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/emergencySMSMeno"/>
<EditText
android:id="#+id/menoEdit"
style="#style/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:textColor="#000"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="3">
<TextView
android:id="#+id/pohlavieLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/emergencySMSPohlavie"/>
<Spinner
android:id="#+id/spinnerPohlavie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="#+id/vekLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/emergencySMSVek"/>
<EditText
android:id="#+id/vekEdit"
style="#style/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"
android:textColor="#000"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:id="#+id/vahaLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/emergencySMSVaha"/>
<EditText
android:id="#+id/vahaEdit"
style="#style/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"
android:textColor="#000"/>
</LinearLayout>
<TextView
android:id="#+id/alergieLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:text="#string/emergencySMSAlergie"/>
<EditText
android:id="#+id/alergieEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textColor="#000"/>
<TextView
android:id="#+id/chorobyLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:text="#string/emergencySMSChoroby"/>
<EditText
android:id="#+id/chorobyEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textColor="#000"/>
<TextView
android:id="#+id/zraneniaLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:text="#string/emergencySMSZranenie"/>
<EditText
android:id="#+id/zraneniaEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:lines="3"
android:textColor="#000"/>
<TextView
android:id="#+id/polohaLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:text="#string/emergencySMSAktualnaPoloha"/>
<EditText
android:id="#+id/polohaEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textColor="#000"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<Button
android:id="#+id/odoslatButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/send"
android:layout_weight="1"/>
<Button
android:id="#+id/zrusitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/emergencySMSZrusit"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
It shows scrollView and two buttons bellow it. I am not exactly sure what you want to do but as far as I can see you are doint it wrong. ScrollView can take only one child element but you have set scrollview as your main parent but then you put more child inside it.
Also you are doing another mistake. You dont need to use linear layouts (in most cases) if they have only one child. It is bad for performance.
Change the value of the attribute layout_height to match_parent so that the ScrollView take up the whole screen and hence enable scrolling. The correct code is
<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:layout_gravity="center_vertical" >
<LinearLayout
android:id="#+id/LinearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/back"
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:scrollbarAlwaysDrawVerticalTrack="false"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical"
tools:context="com.nadusha.phonebook.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Info"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="#+id/nameTextLayout"
android:orientation="horizontal"
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/nameTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<requestFocus />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"/>
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/mobileNoTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/homeNoTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-Mail "
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_marginBottom="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/emailTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/saveBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:textColor="#FFFFFF"/>
<Button
android:id="#+id/cancelBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/viewBtn"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ViewContact"
android:textColor="#FFFFFF" />
</Linearlayout>
</LinearLayout>
You could try changing
android:layout_height="466dp"
to
android:layout_height="wrap_content"
or
android:layout_height="match_parent"
Im having trouble aligning my button and textbox at the bottom of the page. Also may relative layout messed up. How do I add a view with the current conversation. my Listview is not working. I want to attain a simple design like this
here is my code. Also the grey is overlaying my app and i can't see my listview
<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"
tools:context=".MainActivity" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
/>
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
android:background="#color/gray"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:paddingTop="5dp" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:inputType="textMultiLine"
android:lines="3"
android:maxLines="3"
android:minLines="1"
android:scrollbars="vertical" />
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:gravity="center"
android:text="#string/send"
android:textSize="15sp"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
but my output looks like this
Try this..
<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"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.7"
android:gravity="center"
android:inputType="textMultiLine"
android:lines="3"
android:maxLines="3"
android:minLines="1"
android:scrollbars="vertical"/>
<Button
android:id="#+id/send"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.3"
android:gravity="center"
android:text="#string/send" />
</LinearLayout>
</RelativeLayout>
Or
<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"
tools:context=".MainActivity" >
<Button android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/send" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:layout_toLeftOf="#+id/send"
android:lines="3"
android:maxLines="3"
android:minLines="1"
android:scrollbars="vertical"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
EDIT:
<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:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false" />
</LinearLayout>
<LinearLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/gray" >
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.8"
android:gravity="center"
android:inputType="textMultiLine"
android:lines="3"
android:maxLines="3"
android:minLines="1"
android:scrollbars="vertical" />
<Button
android:id="#+id/send"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.2"
android:gravity="center"
android:text="#string/send"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
you should put your EditText and Button inside a LinerLayout(horizontal)
<LinearLayout android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content" <!-- or give some dimension -->
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="3"
android:maxLines="3"
android:minLines="1"
android:scrollbars="vertical"
/>
<Button android:id="#+id/send"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/send" />
</LinearLayout>
Try below 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"
tools:context=".MainActivity" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:inputType="textMultiLine"
android:lines="3"
android:maxLines="3"
android:minLines="1"
android:layout_toLeftOf="#+id/send"
android:scrollbars="vertical" />
<Button
android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="send" />
</RelativeLayout>
It is looking like this.
use this:
<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"
tools:context=".MainActivity" >
<Button android:id="#+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/send" />
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:layout_toLeftOf="#id/send"
android:lines="3"
android:maxLines="3"
android:minLines="1"
android:scrollbars="vertical"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Add a LinearLayout inside your main relative layout, and add your EditText and Button inside that LinearLayout. Don't forgat to add property android:layout_weight="1" to your elements. like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="3"
android:maxLines="3"
android:minLines="1"
android:scrollbars="vertical"
android:layout_weight="1"/>
<Button
android:id="#+id/send"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/send" />
</LinearLayout>
So I am a beginner at layouts in Android and I am learning RelativeLayout. I am attempting to make the following:
However, all I get in my virtual device is the name field taking up 100% of the space (width and height).
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/root">
<EditText android:id="#+id/name"
android:layout_alignParentLeft="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint = "Name"/>
<EditText android:id="#+id/phone"
android:layout_below="#id/name"
android:layout_alignParentRight="true"
android:layout_weight="0.4"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="Phone" />
<EditText android:id="#+id/email"
android:layout_below="#id/phone"
android:layout_alignParentRight="true"
android:layout_weight="0.4"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="Email" />
<EditText android:id="#+id/dob"
android:layout_below="#id/email"
android:layout_alignParentRight="true"
android:layout_weight="0.4"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:hint="D.O.B." />
<EditText android:id="#+id/address"
android:layout_below="#id/phone"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/dob"
android:layout_weight="0.6"
android:layout_height="0dp"
android:layout_width="match_parent"
android:hint="Address" />
<Button android:id="#+id/submit"
android:layout_weight="1.0"
android:layout_below="#id/address"
android:layout_height="match_parent"
android:layout_width="0dp"
android:text="Submit"/>
</RelativeLayout>
What is going wrong?
Here is the xml for your output.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:hint="Name" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true
android:layout_weight="-10"
android:hint="Phone" />
<EditText
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/phone"
android:layout_weight="0.4"
android:hint="Email" />
<EditText
android:id="#+id/dob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/email"
android:layout_weight="0.4"
android:hint="D.O.B." />
<EditText
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/phone"
android:layout_toLeftOf="#id/dob"
android:layout_weight="0.6"
android:hint="Address" />
</RelativeLayout>
<Button
android:id="#+id/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
Change the layout_height for the name element to:
android:layout_height="wrap_content"
Change your Layout XML to the above:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:hint="Name" />
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/name"
android:orientation="horizontal"
android:layout_marginBottom="60dp"
android:weightSum="1" >
<EditText
android:id="#+id/address"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:hint="Address" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.4"
android:weightSum="3" >
<EditText
android:id="#+id/phone"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Phone" />
<EditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Email" />
<EditText
android:id="#+id/dob"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="D.O.B." />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/submit"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:text="Submit" />
</RelativeLayout>
Hope that helps:)