android中的按钮重叠

时间:2012-08-16 10:01:09

标签: android xml

我的XML文件中有两个按钮

<Button
    android:id="@+id/button1"
    android:layout_width="60dp"
    android:layout_height="65dp"
    android:layout_alignBottom="@+id/img"
    android:layout_alignParentRight="true"
    android:background="@android:color/transparent" />

<Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="65dp"
    android:layout_alignBottom="@+id/img"
    android:layout_alignParentRight="true"
    android:background="@android:color/transparent" />

现在在我的java代码中,我希望启用第一个按钮并根据某些逻辑禁用第二个按钮,反之亦然。 我试过了 -

button1.setenabled(true);
button2.setenabled(false);

但是在这种情况下,两个按钮都被禁用,因为button1算出父按钮,一旦它被禁用,它下面的按钮也会被禁用。 请帮忙解决这种情况。

2 个答案:

答案 0 :(得分:0)

禁用顶视图不会让触摸事件传递到其下方的视图。你将不得不尝试其他一些东西才能得到这个。

您能解释一下您在这里想要达到的目标吗?

答案 1 :(得分:0)

非常感谢你们的时间。我找到了解决方案。 我正在禁用基于某些条件的按钮并启用另一个按钮,但它们是重叠的,当我在视图顶部禁用按钮时,视图下方的按钮也被禁用,即使下面的按钮已启用。 我用过 -

button1.bringToFront();

现在工作正常。

谢谢Chitranshu Asthana ..你的回答暗示了我