Android button overlapping text layout when typing - android

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.

Related

UI Design Issue

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>

Adjust xml android with imageView,button and text

There has a listView and imageView in Activity A. If listView.size is equal to 0, it will display the image in the imageView, it not equal to 0, it will display the list.
This is the xml of my Activtiy A. I want to make the text and button display below the image but I found it so difficult to adjust.
<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="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<ImageView
android:src="#mipmap/data"
android:paddingTop="30dp"
android:layout_gravity="center"
android:layout_width="330dp"
android:layout_height="300dp"
android:id="#+id/imageView2"
android:paddingLeft="20dp"></ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Data"
android:textSize="15dp"
android:layout_marginLeft="140dp"
android:paddingTop="160dp"
android:textColor="#color/honey_dew2"
android:layout_gravity="center"
android:id="#+id/NoData"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Data"
android:paddingTop="20dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="130dp"
android:id="#+id/button2"
android:layout_centerVertical="true" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView2"
android:layout_weight="1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
</RelativeLayout>
This is what I want. Thanks
http://i.stack.imgur.com/OSL4I.png
I think this is pretty much what you are looking for
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:src="#mipmap/data"
android:paddingTop="30dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="No alarms"
android:textSize="15sp"
android:textColor="#color/honey_dew2"
android:id="#+id/NoData"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="Add alarms"
android:paddingTop="48dp"
android:id="#+id/button2" />
</LinearLayout>
Notice that I changed from a RelativeLayout to a LinearLayout with a orientation value of vertical. I think that the RelativeLayout adds unnecessary complexity to this problem.
By using the layout_centerVertical and layout_centerHorizontal attributes instead of the padding you solve two problems at once.
The position now scales to different devices.
The layout is far less complex.
Notice also that the TextView textSize attribute is now in the units sp (scaling pixels) instead of dp (density-independent pixels). The size of your text should always be defined in sp and the size of your views should be defined either relatively or in dp.
This tutorial from the prolific mkyong should provide a strong foundation for manipulating the XML with your Java code.
I'd rework your entire approach. Use ListView.setEmptyView(View) to set a separate view to display when the list is empty. Then your base layout is just the list, and you have a separate layout for what to display for the empty case.

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

EditText and Button side by side

I want to present in my layout an EditText and a Button side by side with a small space (margin) between them. I don't want to set a fixed size (I think that's a bad habit).
How to do that?
My Try:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_alignParentLeft="true" />
<Button
android:id="#+id/btn_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:text="Search" />
</RelativeLayout>
You're using a RelativeLayout; however, you cannot created a flexible design within that type of ViewGroup. You must use a LinearLayout.
We use android:layout_weight="1" along with the android:layout_width="0dp" to create a flexible control. Adjust the weight number for different size ratios.
Afterwards, we use android:layout_margin on both controls so the resulting weighted size of each is equal.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="8dp" />
<Button
android:id="#+id/btn_search"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Search"
android:layout_marginLeft="8dp" />
</LinearLayout>
You can use Linear layout with horizontal orientation and add an EditText and Button in the following way
<LinearLayout
orientation="horizontal"
layoutwidth="match_parent"
layoutheight="wrap_content">
<EditText
layoutwidth="0dp"
layoutheight="wrap"
layout_weight=".8"/>
<Button
layoutwidth="0dp"
layoutheight="wrap"
layout_weight=".2"/>
</LinearLayout>
Hope this will solve your problem. Make sure to change the weights according to your needs.
Thanks
Use Linear layout to show both side by side and use 'match_parent' and 'wrap_content' appropriately.
Here's a piece of xml code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" >
<EditText
android:id="#+id/et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go!!" />
</LinearLayout>

How to set the size of layout more efficiently?

I need my view to be placed in the center and it's width is not a match parent or wrap content but a size of particular percentage of a screen the app is running on. To have a more flexible layout I didn't set its size using dimensions, but defined weights for the elements to have a required size of the main one. In order to do so I've inserted two additional LinearLayouts and defined weights for them. I don't think this is the best solution to increase Views amount within the XML. Can you guys let me know the more efficient way of doing that?
<?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:background="#drawable/right_back"
android:orientation="horizontal"
android:gravity="center">
<!-- The first one I think which is redundant -->
<LinearLayout
android:layout_weight="25"
android:layout_width="0dip"
android:layout_height="wrap_content"/>
<!-- Main view I need to be of a required size on each screen size -->
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:background="#drawable/layout_round_corners"
android:orientation="vertical"
android:layout_weight="50"
android:padding="20dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/welcome_text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/text_color"
android:layout_gravity="center_horizontal"/>
<EditText
android:id="#+id/edt_firsttimeactivity_first_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/password"
android:password="true"
android:singleLine="true"/>
<EditText
android:id="#+id/edt_firsttimeactivity_second_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/repeat_new_password_again"
android:password="true"
android:singleLine="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="onButtonClick"
android:text="#string/create_account_for_me"/>
</LinearLayout>
<!-- The second one I think which is redundant -->
<LinearLayout
android:layout_weight="25"
android:layout_width="0dip"
android:layout_height="wrap_content"></LinearLayout>
</LinearLayout>
This is how you should write the layout:
<?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="horizontal"
android:background="#drawable/right_back"
android:weightSum="1"
android:gravity="center">
<!-- Main view I need to be of a required size on each screen size -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/layout_round_corners"
android:layout_weight=".5"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/welcome_text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/text_color"
android:layout_gravity="center_horizontal"/>
<EditText
android:id="#+id/edt_firsttimeactivity_first_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/password"
android:password="true"
android:singleLine="true"/>
<EditText
android:id="#+id/edt_firsttimeactivity_second_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/repeat_new_password_again"
android:password="true"
android:singleLine="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="onButtonClick"
android:text="#string/create_account_for_me"/>
</LinearLayout>
</LinearLayout>
Try this. You can change the layout_weight of the 2nd LinearLayout to make it look big or small as you like.
I believe the problem is that you haven't defined a weightSum. You should add android:weightSum="100" (for example) to your outermost LinearLayout, and then divide that sum however you want into your inner layouts.
Edit: If I understood the issue correctly, I think you should be able to solve the problem by simply using android:paddingLeft and android:paddingRight for your "main view". You could also try android:layout_marginLeft and android:layout_marginRight. Of course, leaving the height as fill_parent in this case. Hope that helps.

Categories

Resources