How to add overlay view over other view in android?

前端 未结 3 1785
不思量自难忘°
不思量自难忘° 2021-01-11 17:41

I want to put button above image view.

How can i do this?

(Please, don\'t offer to set Background, cause i need ImageView)

相关标签:
3条回答
  • 2021-01-11 17:54

    Worked for me with both ImageView and Button inside RelativeLayout:

     <Button android:layout_centerInParent="true">
    

    ...

    0 讨论(0)
  • 2021-01-11 17:56

    Set as background!

    Just kidding... what you need is put your views inside a RelativeLayout. Something like will work:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">
      <ImageView
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
        <Button
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_alignParentLeft="true"
           android:layout_alignParentBottom="true"
           android:text="blah blah"/>
    </RelativeLayout>
    

    Notice the use of params like layout_alignParentLeft which are used to position the view where you want.

    0 讨论(0)
  • 2021-01-11 18:13

    I agree with @Cristian's answer. but also, If you need button's action listener you can add onClick method to your imageView without using button.

    And also ImageButton. I hope this answer shows some path to solve your problem.

    0 讨论(0)
提交回复
热议问题