Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Android上,当按钮处于线性布局时,单击不触发_Java_Android_Android Layout_Android Button - Fatal编程技术网

Java 在Android上,当按钮处于线性布局时,单击不触发

Java 在Android上,当按钮处于线性布局时,单击不触发,java,android,android-layout,android-button,Java,Android,Android Layout,Android Button,因此,我尝试制作一些类似于snapchat在选项菜单中所做的操作,在该菜单中,您可以向下滑动,仍然可以在背景中看到相机。我不会发布所有代码,但我已经调试了导致问题的原因。我是android开发者的新手,但我以前做过一些java编程 这是我的xml <me.dontenvy.videotest.MainMenu xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_

因此,我尝试制作一些类似于snapchat在选项菜单中所做的操作,在该菜单中,您可以向下滑动,仍然可以在背景中看到相机。我不会发布所有代码,但我已经调试了导致问题的原因。我是android开发者的新手,但我以前做过一些java编程

这是我的xml

<me.dontenvy.videotest.MainMenu xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000"
    android:orientation="vertical"
    android:animateLayoutChanges="true"
    android:id="@+id/main_menu">

<!-- this is for the camera -->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/camera_container">

    <TextureView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/texture"
        android:animateLayoutChanges="true"/>

</RelativeLayout>

<!-- this is for the overlay menu -->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/slide_menu"
    android:animateLayoutChanges="true"
    android:background="@drawable/transparent_background">

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/clear_background"
        android:layout_alignParentBottom="true"
        android:id="@+id/slide_button"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <Button
            android:layout_width="@dimen/circle_nav_button_diameter"
            android:layout_height="@dimen/circle_nav_button_diameter"
            android:background="@drawable/circle_button"
            android:backgroundTint="#050"
            android:id="@+id/take_image_nav_button"/>
    </LinearLayout>
</RelativeLayout>
</me.dontenvy.videotest.MainMenu>

我在MainMenu.java类中添加了onClick侦听器,该类扩展了RelativeLayout。下面是代码其余部分的要点


问题是当@id/take\u image\u nav\u按钮在LinearLayout中时,onClick操作不起作用,当我将其从LinearLayout中取出时,onClick操作起作用。感觉线性布局在某种程度上阻碍了单击。我在stackoverflow和其他谷歌搜索上做了很多尝试,但似乎没有什么能解决这个问题

在您设置的按钮的线性布局父项上,但这会使其内部的所有内容都不可点击。要修复它,请将
false
更改为
true

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:clickable="true"> // Change here to true, like this
//将此处更改为true,如下所示

或者干脆删除这个属性

你能添加主代码的相关部分吗?我把它添加到了一个要点中,只是尝试了一下,它不起作用,也尝试了去掉它,它不起作用。更新posting@LuisFHernandez好的,对不起。如果你把它放在线性布局的正上方,它就可以点击了,对吗?因为在第一个布局上有另一个
android:clickable=“false”
,但是如果按钮在它内部工作,那么我移除这个atribute可能是错误的。我取出了另一个
android:clickable=“false”
,我没有注意到它在那里。基本上,如果我将
@id/take_image\u nav_按钮
从其父线性布局中取出,并将其放在
@id/slide_菜单
RelativeLayout中,它就会工作,我可以单击它。但是当它在
@id/slide\u菜单中的线性布局中时,如果它不工作,我就不能单击它。