Reputation: 87
I am doing some XML for an android app.
I have images, text, and button in my view.
I used a Linear layout, but I think it's not what I need.
I would like to set my last button to 80 dp from the bottom screen. Regardless the smartphone and the size of the screen. I want my button to be at 80 dp from the bottom of all device.
I have no idea how to do it if someone can help me it could be cool!
I tried with a LinearLayout but i think i can't do it.
Now I'm trying with a constraintLayout but I'm not sure it will work.
Thanks
Upvotes: 0
Views: 57
Reputation: 87
I finally found a solution with constraint layout.
I'm using app:layout_constraintBottom_toBottomOf to align my button to the bottom of my screen then i use a marginBottom. Thanks for all for your response, i will try it with a relative layout :)
Upvotes: 0
Reputation: 23
You can do it with a RelativeLayout
and layout_alignParentBottom
take a look at this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textview1"/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="@+id/textview1"/>
<Button
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Button"
android:layout_marginBottom="80dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Upvotes: 0
Reputation: 1
Use Relative layout as parent layout not Linear Layout after that use this code ADD Views inside this Relative Layout whatever you want to add like Textview etc.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button at bottom"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"/>
</RelativeLayout>
Upvotes: 0
Reputation: 427
This is one of the ways to achieve your goal using Relative layout as parent:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom Button"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"/>
</RelativeLayout>
Upvotes: 2