UI Design Issue - android

I am new to Android. I am creating a layout for a registration form. Base container I am using as relative layout. Inside relative layout i am keeping liner layout container and then inside this all components of a registration form.
But after drooping two edit text field inside liner layout I can see both the edit text field are overlapping each other and it is visible as one and also moving towards center in liner container. Hope so understood. Well I need components one after one horizontally. Help?
<?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:background="#color/colorAccent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:background="#drawable/l_border"
android:padding="30dp"
>
<EditText
android:id="#+id/txtMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/ll_border"
android:backgroundTint="#color/colorAccent"
android:hint="Enter Name"
android:padding="10dp"
android:textColorHint="#color/colorBlack" />
<EditText
android:id="#+id/txtName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/ll_border"
android:backgroundTint="#color/colorAccent"
android:hint="Enter Mobile"
android:padding="10dp"
android:textColorHint="#color/colorBlack" />
</LinearLayout>
</RelativeLayout>
[

First of all, unless you want to add something over your inner LinearLayout, there is no point in nesting it inside the RelativeLayout.
Second, your inner LinearLayout has no orientation set, so by default is set to horizontal which means the first edit text (layout_width="match_parent") will push out of the screen the second EditText.
If you set the orientation for the inner LinearLayot, to "vertical", you will be able to see both fields.
If you want to have both edit texts, placed horizontally, set the "layout_width"="0; "weight"="1 on both of the text fields. Or you can play around with the RelativeLayout positioning.
UPDATE -- Suggested by #petey
Here's a way to achieve what you want:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" // this view is kind of pointless
android:background="#color/colorAccent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:background="#drawable/l_border"
android:padding="30dp">
<EditText
android:id="#+id/txtMobile"
android:layout_width="0dp" // NOTICE THIS
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1" // // NOTICE THIS
android:background="#drawable/ll_border"
android:backgroundTint="#color/colorAccent"
android:hint="Enter Name"
android:padding="10dp"
android:textColorHint="#color/colorBlack" />
<EditText
android:id="#+id/txtName"
android:layout_width="0dp" // NOTICE THIS
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1" // NOTICE THIS
android:background="#drawable/ll_border"
android:backgroundTint="#color/colorAccent"
android:hint="Enter Mobile"
android:padding="10dp"
android:textColorHint="#color/colorBlack" />
</LinearLayout>

Related

Switch right of TextInputLayout Android

I would like to place a Switch right of a TextInputLayout, with match_parent parameters on the TextInput and a margin.
Placing the switch to the left seems to work, however it is hidden when placing it to the right.
See the two images below:
As you can see the switch places itself wrongly.
Here is my XML code. The main layout is a CoordinatorLayout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Social Networks"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/colorPrimary"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp">
<android.support.design.widget.TextInputEditText
android:id="#+id/myprofile_google"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:textColor="#color/blue_grey_800"
android:layout_height="wrap_content"
android:hint="Google +" />
</android.support.design.widget.TextInputLayout>
<Switch
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Change the layout_width of your TextInputLayout to 0dp, and add this attribute to it as well:
android:layout_weight="1"
What's happening right now is that your TextInputLayout has a width of match_parent. What this will do is fill the entire remaining space of the parent (this is somewhat unique to LinearLayout). When your Switch is on the left, it gets enough space for it and then the TextInputLayout takes up the rest. However, when the Switch is on the right, the TextInputLayout takes up all the space first!
Using weight instead will make sure that other components get the space they need before the weighted component gets the extra space.
You're missing two bits in your XML.
Firstly, the orientation on your linear layout containing both your input layout and switch. Secondly, use weighting to show both items as you've specified that the text input layout should match the parent (fill the view width in this case).
This layout produces your desired output:
<?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="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Social Networks"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Medium"
android:textColor="#color/colorPrimary"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="40dp">
<android.support.design.widget.TextInputEditText
android:id="#+id/myprofile_google"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:textColor="#android:color/holo_red_dark"
android:layout_height="wrap_content"
android:hint="Google +" />
</android.support.design.widget.TextInputLayout>
<Switch
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
I would suggest you use RelativeLayout instead of LinearLayout, or even better redo the whole layout in a ConstraintLayout.
The RelativeLayout implementation would probably be something like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:id="#+id/textInputLayout"
android:layout_toStartOf="#+id/switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp">
<android.support.design.widget.TextInputEditText
android:id="#+id/myprofile_google"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:textColor="#color/blue_grey_800"
android:layout_height="wrap_content"
android:hint="Google +" />
</android.support.design.widget.TextInputLayout>
<Switch
android:id="#+id/switch"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_gravity="center_vertical"/>
</LinearLayout>

Android button overlapping text layout when typing

I am programming an Android app which has an initial screen that works fine. The problem is that, when typing, a button overlaps the text, as you can see here:
Here is the code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<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.app.InitialActivity"
tools:showIn="#layout/activity_initial">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Welcome to app"
android:layout_marginTop="50dp"
android:id="#+id/textViewTitle"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:id="#+id/editTextEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textViewTitle"
android:layout_marginLeft="15dp"
android:layout_marginTop="50dp"
android:layout_marginRight="15dp"
android:inputType="textEmailAddress"
android:textSize="17sp"
android:hint="Enter your email"
android:ems="10" />
<EditText
android:id="#+id/editTextPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editTextEmail"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="15dp"
android:inputType="textPassword"
android:textSize="17sp"
android:hint="Enter your password"
android:ems="10" />
<Button
android:id="#+id/loginButton"
android:text="Login"
android:layout_centerVertical="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editTextPassword"
android:layout_marginLeft="15dp"
android:layout_marginTop="25dp"
android:layout_marginRight="15dp" />
<Button
android:id="#+id/registerButton"
android:text="Register"
android:layout_centerVertical="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/loginButton"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:layout_marginRight="15dp" />
<Button
android:id="#+id/forgotPasswordButton"
android:text="Forgot Password?"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp" />
</RelativeLayout>
</ScrollView>
Any help will be much appreciated, thanks in advance.
When I was starting with Android development I was used to work with RelativeLayout too (I'm not an expert, I'm just telling my experience). At first, it looks like the most appropriate layout, but one thing that you should keep in mind is: let the system take care of the things to you, in other words, RelativeLayout is totally dependent from what you're saying, so with you don't think about new screen resolution, or an old one, the whole layout could become a mess.
The goal is, tell the Android what you want without using specific parameters (or at least try to avoid those). I agree with #klaymen: for different orientations you should use more than just one layout.
Just for an example, see the code below (it's a remake of your code):
<?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_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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.app.InitialActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Welcome to app"
android:id="#+id/textViewTitle" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/editTextEmail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:textSize="17sp"
android:hint="Enter your email"
android:ems="10" />
<EditText
android:id="#+id/editTextPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textSize="17sp"
android:hint="Enter your password"
android:ems="10" />
<Button
android:id="#+id/loginButton"
android:text="Login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/editTextPassword" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:weightSum="2"
android:orientation="horizontal">
<Button
android:id="#+id/registerButton"
android:text="Register"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/forgotPasswordButton"
android:text="Forgot Password?"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
There's a little things here that are importants and could help you a lot in the next tries (look for these properties in the code above):
android:layout_gravity;
Standard gravity constant that a child supplies to its parent. Defines how the child view should be positioned, on both the X and Y axes, within its enclosing layout.
android:gravity;
Specifies how an object should position its content, on both the X and Y axes, within its own bounds.
android:weightSum;
Defines the maximum weight sum. If unspecified, the sum is computed by adding the layout_weight of all of the children. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.
Must be a floating point value, such as "1.2".
This may also be a reference to a resource (in the form "#[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.
This corresponds to the global attribute resource symbol weightSum.
android:layout_weight;
LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view. Child views can specify a weight value, and then any remaining space in the view group is assigned to children in the proportion of their declared weight. Default weight is zero.
I hope that helps you. One more thing use your IDE in favor, generate some examples and look how they work (they used to be dynamic), I'm pretty sure that you will learn a lot with this exercise.
Good Luck!
One way to overcome this problem would be to use android:windowSoftInputMode="adjustNothing" inside your activity tag.
<activity name="YourActivity"
android:windowSoftInputMode="adjustNothing">
...
</activity>
However, keep in mind that in this case the register button will be covered by the keyboard.
You have set each view relative to another in the page.
You'd better place all of your elements in the page relative to one element or relative to main layout.
This problem is because of using "Relative Layout".
Another option is using an simpler layout like linear layout inside the relative layout to simplify things.

XML Margins not what I expect, all on same "line", not stacked

I'm following this tutorial and have the program working technically, only the Button and Image are inline with the display and text entry box.
I want it to look like the image below, but instead it has all of those elements on one horizontal line.
Image: How I want it to look like:
Here's the activity_main.xml
<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"
tools:context=".MainActivity">
<TextView
android:id="#+id/main_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="#string/textView"/>
<!-- Displays keyboard when touched -->
<EditText
android:id="#+id/main_edittext"
android:inputType="textCapSentences"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:hint="#string/hint"/>
<!-- List whose dataset is defined in code with an adapter -->
<ListView
android:id="#+id/main_listview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="20dp"/>
<!-- Set OnClickListener to trigger results when pressed -->
<Button
android:id="#+id/main_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="#string/button" />
<!-- Shows an image from your drawable resources -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:src="#drawable/ic_launcher" />
<!-- Closing tag for the horizontal nested layout -->
</LinearLayout>
Do you need the MainActivity.java? If so, I'll post it. That part works, I can get input from keyboard, and it displays - and if the string is long enough, will fill to the right, pushing everything else over.
I understand that's from the wrap_content property, right?
Final thought: The tutorial says
Add the EditText XML to activity_main.xml as a sibling to the TextView
and the horizontal LinearLayout.
I wasn't sure what it means to make it a sibling, so I just put it after TextView, as you may see. Does that have anything to do with it?
Thanks for any ideas or advice! (Sorry if the title is a little convoluted.)
edit: There was a comment basically saying to add android:orientation="vertical" to the top <LinearLayout xmlns:android... > part. That worked! Only now the button and image are pushed down to the bottom of the screen, while the text entry box and display are up top...so lots of white space. I thought that I had set them to all be 20dp separate from eachother?
Edit2: I fixed, kind of, that spacing issue by setting <textWidth>, <EditText>, and <Button> to have android:layout_width="match_parent"
android:layout_height="wrap_content". ...but now they are horizontal (yay!) but not like the screenshot. How do I get them lined up like that?
try this
<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">
<TextView
android:id="#+id/main_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="textView"/>
<!-- Displays keyboard when touched -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/main_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="button" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<EditText
android:id="#+id/main_edittext"
android:inputType="textCapSentences"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:hint="hint"/>
<!-- List whose dataset is defined in code with an adapter -->
<ListView
android:id="#+id/main_listview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="20dp"/>
<!-- Closing tag for the horizontal nested layout -->
</LinearLayout>

views get hide on orientation change from portrait to landscape in android mobile application

there is an activity in my application. In this i am taking few values from user using some Editboxes. the problem is that if the phone's orientation is portrait then i can see all the EditBoxes and buttons but when the orientation changes to landscape the buttons get hide and i can see only the first 3 Editboxes and nothing else. All i want is that if such a case appears and the size of the layout gets more than a height of phone, then a scroll should appear so that i can scroll down to see the below fields and buttons. Is there a better way to do it ???? (using a different layout for landscape mode will cause recreating the activity which i do not want)
Below is the code for my activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.name.package.service">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/title_text_size"
android:textStyle="bold"
android:gravity="center_horizontal"
android:id="#+id/tv_lable"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_serivce_description"
android:gravity="left"
android:text="#string/plumber_service_description"
android:textSize="#dimen/description_text_size"
android:layout_marginTop="#dimen/large_margin"
android:layout_below="#id/tv_book_service_title_lable"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name :"
android:id="#+id/tv_customer_name_label"
android:layout_below="#id/tv_serivce_description"
android:layout_marginTop="#dimen/huge_spacing"
android:textSize="#dimen/label_text_size"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_customer_name"
android:layout_alignBottom="#id/tv_customer_name_label"
android:layout_toRightOf="#id/tv_customer_name_label"
android:layout_marginLeft="#dimen/normal_margin"
android:hint="fiil your name"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email :"
android:id="#+id/tv_customer_email_label"
android:layout_below="#id/tv_customer_name_label"
android:layout_marginTop="#dimen/large_spacing"
android:textSize="#dimen/label_text_size"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_customer_email"
android:layout_alignBottom="#id/tv_customer_email_label"
android:layout_toRightOf="#id/tv_customer_email_label"
android:layout_marginLeft="#dimen/normal_margin"
android:hint="fiil your email"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact :"
android:id="#+id/tv_customer_contact_label"
android:layout_below="#id/tv_customer_email_label"
android:layout_marginTop="#dimen/large_spacing"
android:textSize="#dimen/label_text_size"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_customer_contact"
android:layout_alignBottom="#id/tv_customer_contact_label"
android:layout_toRightOf="#id/tv_customer_contact_label"
android:layout_marginLeft="#dimen/normal_margin"
android:hint="fiil your email"
android:gravity="center_horizontal"
android:marqueeRepeatLimit="marquee_forever"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv_service_description_label"
android:text="Description"
android:textSize="#dimen/label_text_size"
android:layout_below="#id/tv_customer_contact_label"
android:layout_marginTop="#dimen/large_spacing"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et_service_description"
android:layout_below="#id/tv_service_description_label"
android:layout_marginTop="#dimen/large_margin"
android:hint="What service you need ?"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book Service"
android:gravity="center_horizontal"
android:layout_below="#id/et_service_description"
android:layout_marginTop="#dimen/large_margin"
android:layout_centerHorizontal="true"
/>
i have also used below settings for the activity in manifest file
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleTop"
Thanks in advance for sharing the knowledge ....:D
Wrap your layout which is RelativeLayout within a Scrollview. If the layout does not fit within the window then scrolls are enabled for you to scroll and view all your views else they will not be visible on screen.
Usage
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollViewid"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
-------add your RelativeLayout ------
</ScrollView>
A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. 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.
Please use LinearLayout instead of RelativeLayout it will solve your problem

Android center two text fields in a frame layout at the same time

this might have been asked before (and I apologise for that) but I couldn't find it so here I am.
I have a frame layout which is horizontally and vertically centered.There are two editText's in it, and I would like to arrange both of them to the center of the screen while maintaining a certain distance between the two of them.
I hope my drawing can give you an idea of what i want.
I have tried many things, but it seems it wasn't enought.Thanks for the help, and sorry for bothering!
http://oi59.tinypic.com/qxa2vm.jpg
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<EditText
android:id="#+id/editText_nume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="#string/nume" />
<EditText
android:id="#+id/editText_parola"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:text="#string/parola" />
</FrameLayout>
Use LinearLayout instead of FrameLayout. FrameLayout is designed to block out an area on the screen to display a single item.
<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" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<EditText
android:id="#+id/editText_nume"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="#string/nume" />
<EditText
android:id="#+id/editText_parola"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:inputType="textPassword"
android:text="#string/parola" />
</LinearLayout>
</RelativeLayout>

Categories

Resources