Place ImageView over Button android

后端 未结 9 1946
醉话见心
醉话见心 2020-11-30 06:35

I am trying to place an ImageView over a Button using RelativeLayout. Here is my xml:



        
相关标签:
9条回答
  • 2020-11-30 07:17

    I found a solution: simply android:elevation="2dp"

    <Button
            android:id="@+id/btnAccess"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_alignParentBottom="true"
            android:layout_gravity="right|center"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp"/>
    
    <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView4"
            android:background="@drawable/or"
            android:layout_alignBottom="@+id/btnRegister"
            android:layout_centerHorizontal="true"
            android:layout_margin="5dp"
            android:elevation="2dp" />
    
    0 讨论(0)
  • 2020-11-30 07:23

    Actually it's much easier to just set the StateListAnimator to @null

    <Button
        ...
        android:stateListAnimator="@null" />
    

    Source Android 5.0 android:elevation Works for View, but not Button?

    0 讨论(0)
  • 2020-11-30 07:24

    Button is just a TextView with a certain style applied to it, so if you replace Button with TextView you can display an ImageView on top of it. This also works on API < 21.

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