Working with android layout - android

I'm new to android and the positioning elements are way different than as it is for web.
So What I want to do is this:
Login: ______
Password: _____
What I can get is this, by setting the linearLayout to vertical orientation:
Login:
__
Password:
__
Or this, with horizontal orientation:
Login:_____Password:_____
How may I mix it and achieve what I need?
Current 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="wrap_content"
android:orientation="horizontal"
android:id="#+id/mainActivity"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Login:"
android:textSize="14pt"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/loginText"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Senha:"
android:textSize="14pt"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/passText"/>
</LinearLayout>

Nest your linearlayouts. Have a vertical top level linear layout, with 2 horizontal linear layouts inside, each of which does one line of your output.

First of all you should use sp instead of pt for android:textSize.
You can achieve your expected layout using Nested LinearLayout as follows:
<?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/mainActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Login:"
android:textSize="14pt" />
<EditText
android:id="#+id/loginText"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Senha:"
android:textSize="14pt" />
<EditText
android:id="#+id/passText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
However a good practice would be to use ConstraintLayout, which reduces the view hierarchy, as follows:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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/mainActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login:"
android:textSize="14pt"
app:layout_constraintBottom_toBottomOf="#+id/loginText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/loginText"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/textView2"
app:layout_constraintEnd_toEndOf="#+id/textView2"
app:layout_constraintStart_toEndOf="#+id/textView2"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Senha:"
android:textSize="14pt"
app:layout_constraintBaseline_toBaselineOf="#+id/passText"
app:layout_constraintStart_toStartOf="#+id/textView" />
<EditText
android:id="#+id/passText"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/textView2" />
</android.support.constraint.ConstraintLayout>

try this:
you can use linear layout for each block like text view and edit text and set linear layout orientation horizontal
<?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/linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Username"
android:paddingLeft="10dp"
android:textColor="#color/black"
android:textSize="18dp" />
<EditText
android:id="#+id/user_et"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Password:"
android:paddingLeft="10dp"
android:textSize="18dp"
android:textColor="#color/black"/>
<EditText
android:id="#+id/password_et"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#color/black"
android:textColor="#color/white"
android:text="Login"
android:textSize="18dp"
android:textAllCaps="false"
android:layout_marginTop="10dp"/>

It's best practice if you can use ConstraintLayout to decrease layout hierarchy. Otherwise, you can use nested LinearLayout.

Usually on mobile you do not need to use label like in web. setHint on EditText should be enough to make the purpose of the fields clear for your users.
<?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="wrap_content"
android:orientation="horizontal"
android:id="#+id/mainActivity"
tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:hint="Username"
android:inputType="textEmailAddress"
android:id="#+id/usernameEditText"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:id="#+id/passwordEditText"/>
</LinearLayout>
You can also use the material text field if you want something like a label to be always there, https://material.io/design/components/text-fields.html
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Username"/>
</android.support.design.widget.TextInputLayout>

Related

android linearlayout not align right

I have a layout that looks like this:
<?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="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/menu_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackgroundFloating"
android:minWidth="600dp"
app:contentInsetStart="0dp"
android:elevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="end">
<Button
android:id="#+id/confirm_button"
style="?android:attr/buttonBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:text="Confirm"
android:textAllCaps="false" />
<Button
style="?android:attr/buttonBarStyle"
android:id="#+id/reset_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:text="Reset"
android:textAllCaps="false" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/prefer_tags"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
<FrameLayout
android:id="#+id/exclude_tags"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp" />
</LinearLayout>
The confirm button and the reset button are supposed to be on the right of the toolbar. However, they are only there unless there is something in the FrameLayout (either prefer_tags or exclude_tags). You can see from the images below:
How do I always keep my button on the right?
Try replacing
android:layout_width="match_parent"
android:gravity="end"
to
android:layout_width="wrap_content"
android:layout_gravity="end"

Android Studio Layout. won't match parent

Everything looks fine in my previews but when I open the app in an emulator the layout doesn't match parent for length or width. Everything is where it should be within the layout it just doesn't stretch overall with the screen. This is happening in every layout in the app(I'm using fragments). To explain better heres pix:
** What is in the preview(and is what i want)
** What I have
here is the XML.
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="#drawable/hlineand"/>
<TextView
android:id="#+id/userTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User"
android:textAlignment="center"
android:textAppearance="#android:style/TextAppearance.Material.Small"
android:textColor="#android:color/darker_gray"
android:textSize="30dp"/>
<TextView
android:id="#+id/updateTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:text="----"
android:textAlignment="center"/>
<EditText
android:id="#+id/emailEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:ems="10"
android:hint="e-mail"
android:inputType="textEmailAddress"
android:layout_below="#+id/userTextView"
android:layout_centerHorizontal="true"/>
<EditText
android:id="#+id/passwordEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/emailEditText"
android:layout_below="#+id/emailEditText"
android:layout_marginTop="24dp"
android:ems="10"
android:hint="password"
android:inputType="textPassword"/>
<Button
android:id="#+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/passwordEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Login"/>
</RelativeLayout>
This is my content main.xml. Like the first commenter mentioned, it was in there. It worked great when I put in match parent & match parent but not its resizing to some like width 344px & height 590px. Any way I can keep that as match parent??
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.a2.reach.MainActivity"
tools:showIn="#layout/app_bar_main">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="344dp"
android:layout_height="495dp"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
Fixed the content main XML by changing the width height to 0dp instead of match parent & adding the 4 constraints on the bottom of the frame layout. Thank you guys and thank you as well to #Du.fantasy for pointing me in the right direction so fast
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="0dp"
android:layout_height="0dp"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
change the FrameLayout to match_parent from fix width and height
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.a2.reach.MainActivity"
tools:showIn="#layout/app_bar_main">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
As per my knowledge, In your first XML, Your are giving orientation="vertcial" to relative layout. If you want that it should work then you should use Linear layout and use orientation for that layout.
Try using like this in you content XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_blood_g_activity"
android:layout_width="match_parent"
android:orientation="vertical"
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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mature Diabetic Patient"
android:layout_gravity="center"
android:textSize="15dp"/>
<View
android:layout_width="wrap_content"
android:layout_height="30dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Your current Blood Sugar"/>
<View
android:layout_width="20dp"
android:layout_height="60dp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/cbs"
android:inputType="number"
android:hint="mg/dl"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Your Target Blood Sugar"/>
<View
android:layout_width="20dp"
android:layout_height="60dp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tbs"
android:inputType="number"
android:hint="mg/dl"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Humalog/Novalog"
android:id="#+id/btnhnbs"
android:layout_gravity="center"/>
</LinearLayout>
in my variant change size parent Layout - fixed my problem
<FrameLayout
android:id="#+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>

How to nest all views into one view, which is placed vertically central?

Here's my MainActivity.xml where I'm using LinearLayout:
<?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:background="#ffe6cc"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.zorgan.app.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#333"
android:textSize="30sp"
android:textStyle="bold"
tools:layout_editor_absoluteY="116dp" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="#drawable/front"
android:contentDescription="#string/front_desc" />
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
tools:layout_editor_absoluteY="496dp" />
</LinearLayout>
How would I nest these 3 views into one view, so they all sit vertically central?
To vertically center the child views, give android:gravity="center_vertical" to the parent view. In your case, for the LinearLayout.
here try this layout
<?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:background="#ffe6cc"
android:gravity="center"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.zorgan.app.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#333"
android:textSize="30sp"
android:textStyle="bold"
tools:layout_editor_absoluteY="116dp" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="#drawable/front"
android:contentDescription="#string/front_desc" />
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="496dp" />
</LinearLayout>
in this android:gravity="center" is the key parameter.
Replace your code with,
<?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:background="#ffe6cc"
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textColor="#333"
android:textSize="30sp"
android:textStyle="bold"
tools:layout_editor_absoluteY="116dp" />
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center_vertical|center_horizontal"
app:srcCompat="#drawable/front"
android:contentDescription="front_desc" />
<Button
android:id="#+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" />
</LinearLayout>
It is tested and working.

Equal vertical spacing in linear layout not working

Running the below code in ANDROID studio is not giving me the desired result: Please help? I would like the 3 TextViews to be equally spaced out vertically in the screen of the device.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Debanshu"
android:textSize="24sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Chakraborty"
android:textSize="24sp"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Voltas"
android:textSize="24sp"
android:layout_weight="1"/>
</LinearLayout>
I believe you want this (added gravity just for the fun of it):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Debanshu"
android:gravity="center"
android:textSize="24sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Chakraborty"
android:textSize="24sp"
android:gravity="center"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Voltas"
android:textSize="24sp"
android:gravity="center"
android:layout_weight="1"/>
</LinearLayout>
As you LinearLayout height equal to wrap_content its working but as height wrapping view you are not getting desired view
try below making LinearLayout height equal to match_parent
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Debanshu"
android:textSize="24sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Chakraborty"
android:textSize="24sp"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="Voltas"
android:textSize="24sp"
android:layout_weight="1"/>
</LinearLayout>
you can try this its work for me
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Debanshu"
android:background="#ffa905"
android:textSize="24sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chakraborty"
android:textSize="24sp"
android:background="#ffffff"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Voltas"
android:textSize="24sp"
android:background="#008000"
android:layout_weight="1"/>
enjoy!!!

Buttons getting cut off in landscape rotation (Android XML)

When I rotate my screen to landscape mode, a DialogFragment containing this layout is cutting off the two buttons at the bottom:
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alias"/>
<EditText
android:id="#+id/edittext_alias"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:ems="10"
android:layout_marginLeft="4dp"
android:maxLength="30"
android:imeOptions="actionDone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Interests"/>
<EditText
android:id="#+id/edittext_interests"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:ems="10"
android:layout_marginLeft="4dp"
android:maxLength="10"
android:imeOptions="actionDone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bio"/>
<EditText
android:id="#+id/edittext_bio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:ems="10"
android:layout_marginLeft="4dp"
android:maxLines="2"
android:gravity="top"
android:imeOptions="actionDone"
android:requiresFadingEdge="vertical"
android:fadingEdgeLength="20dp"
android:scrollbars="vertical"
android:fadeScrollbars="false"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/button_cancel"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Cancel"
android:layout_weight="1"/>
<Button
android:id="#+id/button_confirm"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="OK"
android:layout_gravity="center_horizontal"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Am I doing something wrong or missing something obvious? How can I get it to force display everything?
I think the case is your screen is simply not large enough to show the whole content. Android does not add the scroll functionality if content is larger then the screen. If this is the case wrap all your views in a ScrollView so that the buttons could be visible after scrolling. Like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Putt all your view here -->
</LinearLayout>
</ScrollView>
</LinearLayout>
Also you may put ScrollView as Your Parent View
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Putt all your view here -->
</LinearLayout>
</ScrollView>

Categories

Resources