简体   繁体   中英

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

图像

Should i use CoordinatorLayout instead of RelativeLayout?

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>

Use this in imageview

android:margin_bottom="50dp";
<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM