I don't know why, but my layout color just stops in the bottom of the screen.
I don't think my code is doing that.
And, by the way, does anyone know where to get ideas from a simple layout like this? TextViews and EditTexts?
Mine looks awful
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/AMOB_gray"
tools:context="com.example.tiagosilva.amob_android.TubeDataFragment" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center"
android:background="#color/AMOB_gray">
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/material"
android:textColor="#color/AMOB_yellow"
android:textSize="25dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/snipperMaterial">
</Spinner>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/diameter"
android:textColor="#color/AMOB_yellow"
android:textSize="25dp" />
<EditText
android:id="#+id/et_diameter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round"
android:ems="10"
android:inputType="number"
android:padding="10dp"
android:text="0"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/thickness"
android:textColor="#color/AMOB_yellow"
android:textSize="25dp"
android:gravity="center"/>
<EditText
android:id="#+id/et_thickness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round"
android:ems="10"
android:inputType="number"
android:padding="10dp"
android:text="0"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/clr"
android:textColor="#color/AMOB_yellow"
android:textSize="25dp"
android:gravity="center"/>
<EditText
android:id="#+id/et_clr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round"
android:ems="10"
android:inputType="number"
android:padding="10dp"
android:text="0"/>
<Button
android:id="#+id/btn_save_tube"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/round_buttons"
android:text="#string/save"
android:textColor="#color/AMOB_gray"
android:layout_marginTop="10dp"/>
</LinearLayout>
</ScrollView>
Instead of this:
<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"
tools:context="com.example.tiagosilva.amob_android.TubeDataFragment" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center"
android:background="#color/AMOB_gray">
Try this
<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"
tools:context="com.example.tiagosilva.amob_android.TubeDataFragment"
android:background="#color/AMOB_gray">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center">
So to move the background color inside the root ViewGroup
Add below line in your scroll view. This will do what you want
android:fillViewport="true"
Related
Below is the image what I required.
You can see there is blue background and inside that, it has
Trailer Number 1 which is textview and 01010 is editext (input field)
Also outside the background, there is delete button near to the blu background.
What I tried is,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#color/app_white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/relative_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/blue_light"
android:layout_marginRight="60dp"
android:layout_marginLeft="60dp">
<TextViewÃ’
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trailer number"
android:padding="#dimen/margin_5"
android:layout_margin="5dp"
android:layout_alignParentLeft="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:text="01010"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:layout_toRightOf="#+id/relative_1"
android:background="#drawable/ic_delete_cion" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
But delete icon is not at all displaying and also line is displaying in 01010 eddittext.
This is my screenshot.
I made some changes in ur layout and it is fit in ur requirement and fit for every device.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/relative_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/default_blue_light">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|start"
android:padding="10dp"
android:text="Trailer number" />
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:background="#null"
android:inputType="number"
android:padding="5dp"
android:text="01010"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/ic_delete_icon" />
</LinearLayout>
you can achive this by only putting android:weightSum into linear layout.
try below code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/app_white"
android:orientation="horizontal"
android:padding="10dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight=".9"
android:background="#color/blue_light"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".7"
android:text="Trailer number" />
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:background="#null"
android:inputType="number"
android:text="01010"
android:textSize="14sp" />
</LinearLayout>
<ImageView
android:layout_width="0dp"
android:layout_height="20dp"
android:layout_weight=".1"
android:layout_gravity="center"
android:background="#drawable/ic_delete_cion" />
</LinearLayout>
Try this xml code : (Please replace dimensions, padding, styles with your own)
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="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#FFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/relative_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:layout_weight="6"
android:background="#f5f5f5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="5dp"
android:gravity="center_vertical"
android:padding="5dp"
android:text="Trailer number" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:inputType="number"
android:text="01010" />
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="8dp"
android:src="#drawable/ic_delete_black_24dp" />
</LinearLayout>
</LinearLayout>
I am facing a problem with ScrollView. When the keyboard is appearing, scrollview is not scrolling till the end of the view.
Here is my layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:text="Add Member"
android:textColor="#FFF"
android:textSize="#dimen/heading_text_size"
android:background="#color/heading"
android:gravity="center"
android:padding="10dp"
android:layout_height="?attr/actionBarSize"/>
<ScrollView
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<EditText
android:id="#+id/search_member_number"
android:layout_width="match_parent"
android:hint="Enter mobile number"
android:layout_weight="3"
android:inputType="phone"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/searchExistingUserButton"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:text="Search"
android:textAllCaps="false"
android:background="#FF9800"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
</LinearLayout>
<EditText
android:id="#+id/txtUsername"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:hint="Enter member name"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtAddress"
android:layout_width="match_parent"
android:hint="Address"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtEmail"
android:layout_width="match_parent"
android:hint="Email"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtContact"
android:layout_width="match_parent"
android:hint="Mobile No"
android:inputType="phone"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtReferredBy"
android:layout_width="match_parent"
android:hint="Referred by"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
<AutoCompleteTextView
android:id="#+id/txtKittyGroups"
android:layout_width="match_parent"
android:hint="Enter kitty group name"
android:layout_margin="10dp"
android:layout_weight="8"
android:layout_gravity="center"
android:textSize="#dimen/admin_setup_buttons_text_size"
android:textColor="#000"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtRepeat"
android:layout_width="match_parent"
android:hint="Enter repeat number"
android:layout_margin="10dp"
android:inputType="number"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/createUserButton"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:text="Create Member"
android:textAllCaps="false"
android:background="#BBDEFB"
android:layout_margin="10dp"
android:padding="10dp"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
I have seen several posts in stackoverflow, but unfortunately none is working. What could be the possible solution?
Thanks in advance.
I think the problem is causing by adjustPan . Where adjust Pan does not resize the window, it pans the view so that whatever has focus is never obscured by the soft keyboard.
Add this to your AndroidManifest.xml . This might do the trick.
Example:
<activity android:name="YourActivity"
android:windowSoftInputMode="adjustResize" />
you need to add <Space/> and
android:layout_height="100dp"
give height static which you want.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:text="Add Member"
android:textColor="#FFF"
android:textSize="#dimen/heading_text_size"
android:background="#color/heading"
android:gravity="center"
android:padding="10dp"
android:layout_height="?attr/actionBarSize"/>
<ScrollView
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<EditText
android:id="#+id/search_member_number"
android:layout_width="match_parent"
android:hint="Enter mobile number"
android:layout_weight="3"
android:inputType="phone"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/searchExistingUserButton"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:text="Search"
android:textAllCaps="false"
android:background="#FF9800"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
</LinearLayout>
<EditText
android:id="#+id/txtUsername"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:hint="Enter member name"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtAddress"
android:layout_width="match_parent"
android:hint="Address"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtEmail"
android:layout_width="match_parent"
android:hint="Email"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtContact"
android:layout_width="match_parent"
android:hint="Mobile No"
android:inputType="phone"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtReferredBy"
android:layout_width="match_parent"
android:hint="Referred by"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
<AutoCompleteTextView
android:id="#+id/txtKittyGroups"
android:layout_width="match_parent"
android:hint="Enter kitty group name"
android:layout_margin="10dp"
android:layout_weight="8"
android:layout_gravity="center"
android:textSize="#dimen/admin_setup_buttons_text_size"
android:textColor="#000"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/txtRepeat"
android:layout_width="match_parent"
android:hint="Enter repeat number"
android:layout_margin="10dp"
android:inputType="number"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/createUserButton"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:text="Create Member"
android:textAllCaps="false"
android:background="#BBDEFB"
android:layout_margin="10dp"
android:padding="10dp"
android:layout_height="wrap_content"/>
<Space
android:layout_width="match_parent"
android:layout_height="100dp" />
</LinearLayout>
</ScrollView>
</LinearLayout></LinearLayout>
Use this in your layout:
android:layout_marginBottom="16dp"
I am trying to achieve the below layout but I am not sure how I can split / have two layouts on one screen, with one being empty and one containing other elements. Like shown in the image below, I want to have layout 1 that contains other elements and layout that is empty. With a divider line between the two layouts.
Any help would be nice, I am not sure where to start. I have came accross having two layouts on 1 screen and splitting them to about 40:60 ratio.
Try to use
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.rushabh_pc.lin.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/textView2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label2"
android:id="#+id/toggleButton"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true"
android:checked="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label 3"
android:id="#+id/lab3"
android:layout_below="#+id/toggleButton"
android:layout_toLeftOf="#+id/toggleButton"
android:layout_toStartOf="#+id/toggleButton" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Label 4"
android:layout_alignBaseline="#+id/lab3"
android:layout_alignBottom="#+id/lab3"
android:layout_toRightOf="#+id/toggleButton"
android:layout_toEndOf="#+id/toggleButton"
android:id="#+id/l4"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="last"
android:layout_below="#id/l4"/>
</RelativeLayout>
Code Below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main3"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.staff.app.Main3Activity"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_orange_light">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textView"
android:layout_centerHorizontal="true"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textView"
android:textSize="20dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/textView1"/>
<LinearLayout
android:id="#+id/linearLyout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="editText1"
android:layout_weight="1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="editText2"
android:layout_weight="1"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textView"
android:textSize="40dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/linearLyout"/>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/black"></View>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"></RelativeLayout>
</LinearLayout>
Use LinearLayout with layout_weight to specify the ratio for the space occupied by each child layout. For a 40:60 split, use the below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="0.4"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/holo_green_light"
android:text="Label"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/holo_blue_bright"
android:text="Label"
android:textSize="30sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_weight="1"
android:background="#android:color/holo_green_light"
android:hint="Textbox1" />
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_weight="1"
android:background="#android:color/holo_green_light"
android:hint="Textbox2" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="0sp"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_weight="1"
android:background="#android:color/holo_blue_bright"
android:text="Label" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6"></LinearLayout>
</LinearLayout>
This is the login activity I want to achieve in my app (Image2). But I do not know how to do so it because I cannot paste the editText, password and button over the white part of the image (the whole image has black border). The app has white background and I want to make the look of the image as curve and to place the other fields under it. For now it looks as image1.
and look this
I also want my image to be aligned to the bottom and its width to be match_parent and the height to be adjusted so that the ratio of the original image is saved on different devices. Here is my XML 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:id="#+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5"
tools:context="com.example.android.start.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
app:srcCompat="#drawable/logo"
android:id="#+id/logo"
android:layout_weight="2"
/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:id="#+id/back"
app:srcCompat="#drawable/image2"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editText3" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:id="#+id/editText2" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_centerInParent="true"/>
</LinearLayout>
You can do something like this
<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:id="#+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5"
tools:context="com.example.android.start.MainActivity">
<ImageView
android:id="#+id/logo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
app:srcCompat="#drawable/logo"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:gravity="center"
app:srcCompat="#drawable/image2">
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:ems="10"
android:inputType="textPassword"/>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Button"/>
</LinearLayout>
Use RelativeLayout instead of LinearLayout it will hopefully solve your problem.
Here is the code I used to achieve the look from Image2:
<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:id="#+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5"
tools:context="com.example.android.start.MainActivity">
<ImageView
android:id="#+id/logo"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
app:srcCompat="#drawable/logo" />
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="#drawable/back"
android:weightSum="2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#C8E6C9"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
android:layout_marginBottom="117dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:text="Sign In"
android:background="#8BC34A"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="11dp" />
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#C8E6C9"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
android:layout_above="#+id/button"
android:layout_alignLeft="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_marginBottom="19dp" />
/>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
I'am having a layout with ScrollView. I'am unable to view all the items as soon as my layout is opened
I'am unable to scroll down complete but after editing something in EditText and if I again scroll I'am able to view all the items.
Please help in solving this issue.
Below is my layout file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_alignParentTop="true"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Diabetes Risk Assesment"
android:textStyle="bold"
android:gravity="center"
android:textSize="20dp"
android:textColor="#00abea"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_diabetesage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp">
<EditText
android:id="#+id/input_diabetes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="number"
android:hint="#string/hint_age"
/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Gender"
android:paddingTop="20dp"
android:textSize="15dp"
android:textStyle="bold"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:id="#+id/diaradiogroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="#+id/rmale"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="#+id/rfemale"/>
</RadioGroup>
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_diabeteswaist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp">
<EditText
android:id="#+id/input_waist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="number"
android:hint="#string/hint_waist"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/strexercise"
android:paddingTop="20dp"
android:textSize="15dp"
android:textStyle="bold"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:id="#+id/diaexxercise">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes"
android:id="#+id/remale"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No"
android:id="#+id/refemale"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/strexercisedaily"
android:paddingTop="20dp"
android:textSize="15dp"
android:textStyle="bold"/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:id="#+id/exercisedaily">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes"
android:id="#+id/redmale"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No"
android:id="#+id/redfemale"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/strparents"
android:paddingTop="20dp"
android:textSize="15dp"
android:textStyle="bold"/>
<Spinner
android:id="#+id/spingender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/spinner_style"
/>
</LinearLayout>
<!--<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>-->
</LinearLayout>
</ScrollView>
Maybe that's because your EditText is being focused by default.
You can remove that by adding this line in your onCreate() in your activity.
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Hope this helps :)
After hours of search i founnd a solution for my problem.
add this attribute in scrollview -- app:layout_behavior="#string/appbar_scrolling_view_behavior"
and remove the same attribute from the ViewPager
So the layout ScrollView should be below
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fillViewport="true">
and ViewPager should be like this
<android.support.v4.view.ViewPager
android:id="#+id/viewpager2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>