无法使视图覆盖FrameLayout中的另一个视图 [英] Can't make a view overlay another view in FrameLayout

查看:131
本文介绍了无法使视图覆盖FrameLayout中的另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将ImageView放在Button的顶部,但是无论选择哪种布局或布局的方式,该按钮都将始终覆盖ImageView……这是我尝试过的FrameLayout的一个示例:

I want to make my ImageView on top of my Button, but the button will always overlay the ImageView , no matter which layout I choose or the way I arrange my layout... this is an example of a FrameLayout that I tried:

只是为了简化我的问题:为什么FrameLayout无法正常工作? (您可以将此代码复制到您的Android Studio中,然后再查看)

just for simplifying my question : Why doesn't the FrameLayout work as it should? (you can copy this code to your Android Studio and see yourself)

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:padding="0.1dp">

    <Button
        android:clickable="false"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:text="135"
        android:background="@android:color/holo_blue_bright"
        android:layout_gravity="center"
        android:id="@+id/buttonText"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/triangle"
        android:id="@+id/triangle"
        android:paddingTop="5dp"
        android:layout_gravity="center_horizontal|bottom" />

</FrameLayout>

推荐答案

我自己通过将 Button 更改为 TextView 解决了这个问题. FrameLayout的默认行为在这里不起作用,因为Android系统始终将Button设置为覆盖其他视图(因此用户将始终能够单击该按钮).

I solved the problem myself by changing the Button to TextView . The FrameLayout default behavior isn't working here because Android system always set Buttons to overlay other views (so the user will always be able to click the button).

这篇关于无法使视图覆盖FrameLayout中的另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆