DmO
DmO

Reputation: 399

Button align to bottom, is been hidden from ImageView

I want to place a button in bottom of my layout. Also i have place an image view with layout_alignParentTop, my proble is that my imageview is hide my button. How can i solve that?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    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="match_parent">

    <Button 
        android:id="@+id/btnGetMoreResults"
        android:layout_height="wrap_content" 
        android:layout_width="match_parent"     
        android:text="Get more"
        android:layout_alignParentBottom="true" />

    <ImageView
        android:layout_alignParentTop="true" 
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/btnGetMoreResults"
        android:id="@+id/imageView1" />

</RelativeLayout> 

Look the picture below

img

Should i use CoordinatorLayout instead of RelativeLayout?

Upvotes: 0

Views: 76

Answers (3)

prescott ua
prescott ua

Reputation: 1

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent">

    <ImageView
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/next_btn"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/next_btn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="next"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 0

kam1234
kam1234

Reputation: 572

Use this in imageview

android:margin_bottom="50dp";

Upvotes: 1

Giovanka Bisano
Giovanka Bisano

Reputation: 205

In your ImageView, don't use

android:layout_alignParentBottom="true"

You must use

android:layout_above="@+id/your_button"

This is the final code, don't forget to modify it for your need

<RelativeLayout
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_alignParentTop="true"
        android:layout_above="@id/button"
        android:layout_width="match_parent"
        android:layout_height="0dp"/>
    <Button
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</RelativeLayout>

Upvotes: 1

Related Questions