How do I align views at the bottom of the screen?
The modern way to do this is to have a ConstraintLayout and constrain the bottom of the view to the bottom of the ConstraintLayout with app:layout_constraintBottom_toBottomOf="parent"
The example below creates a FloatingActionButton that will be aligned to the end and the bottom of the screen.
<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_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout>
For reference, I will keep my old answer.
Before the introduction of ConstraintLayout the answer was a relative layout.
If you have a relative layout that fills the whole screen you should be able to use android:layout_alignParentBottom
to move the button to the bottom of the screen.
If your views at the bottom are not shown in a relative layout then maybe the layout above it takes all the space. In this case you can put the view, that should be at the bottom, first in your layout file and position the rest of the layout above the views with android:layout_above
. This enables the bottom view to take as much space as it needs, and the rest of the layout can fill all the rest of the screen.
Align Multiple Views at the bottom of screen
You are using a RelativeLayout
with two LinearLayout
s.
You should give both your LinearLayout
id
s and after that you will position the other LinearLayout
which you want to be on top by giving it the atrribute
android:layout_above="@id/the_id_of_the_one_you_want_to_be_below"
How to make view align at the bottom
I think you should put your AdView
and FloatActionButton
into the LinearLayout
(set orientation=vertical). The FloatActionButton
is on the right of the LinearLayout
and the AdView
has width="match_parent". The LinearLayout
will be put at the bottom of the screen like you was done with the AdView
.
<?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">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"/>
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#00ff00"/>
</LinearLayout>
Or using ConstraintLayout
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.FloatingActionButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="0dp"
android:layout_height="100dp"
android:background="#00ff00"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
</android.support.constraint.ConstraintLayout>
How to align ViewGroup to the bottom of the screen
Try putting this in your onCreate method.
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.gravity = Gravity.BOTTOM;
getWindow().set attributes(lp);
How to align textview at the bottom of the screen inside a scroll view android
Put this in your activity in side onCreate Method
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
or
In Manifest at your activty:
android:windowSoftInputMode="adjustPan"
How to align 3 Views in the center of the screen in Android
It seems I found the answer. The problem was on the app:layout_constraintBottom_toTopOf="@id/iv_other"
of the v_box_male
. It was referencing the Image View (gender symbol) and not the View (box).
It was also missing the app:layout_constraintVertical_chainStyle="packed"
.
Here's the correct code:
<View
android:id="@+id/v_box_male"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/border"
app:layout_constraintBottom_toTopOf="@id/v_box_other"
app:layout_constraintEnd_toStartOf="@id/v_box_female"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_gender"
app:layout_constraintVertical_chainStyle="packed" />
<View
android:id="@+id/v_box_female"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginStart="10dp"
android:background="@drawable/border"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/v_box_male"
app:layout_constraintTop_toTopOf="@id/v_box_male" />
<View
android:id="@+id/v_box_other"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_marginTop="10dp"
android:background="@drawable/border"
app:layout_constraintBottom_toTopOf="@id/bt_next"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/v_box_male" />
Related Topics
How to Enable Logcat/Console in Eclipse For Android
Android: Retrieving Shared Preferences of Other Application
How to Refresh App Upon Shaking the Device
Self-Signed Ssl Acceptance on Android
How to Delete an Sms in Android Before It Reaches the Inbox
Android Writing Logs to Text File
Error Inflating Class Android.Support.Design.Widget.Navigationview
How to Have Onscrolllistener for a Scrollview
How to Install Google Frameworks (Play, Accounts, etc.) on a Genymotion Virtual Device
Outofmemoryerror: Bitmap Size Exceeds Vm Budget :- Android
Percentage Width in a Relativelayout
Clicking Urls Opens Default Browser
Show Compose Sms View in Android
How to Check If Location Services Are Enabled
Android API 21 Toolbar Padding
Android Room - Simple Select Query - Cannot Access Database on the Main Thread