繁体   English   中英

NavigationDrawer阻止活动上的其他按钮

[英]NavigationDrawer blocks other button on the activity

我正在使用应用程序的UI,并且在实现导航抽屉时遇到问题。 如您在这里看到的,我有一些按钮来管理我的媒体播放器,当我实现导航抽屉时,这些按钮不响应我的点击(在没有导航抽屉的情况下可以正常工作)。

我认为问题出在我的XML文件中,因为删除Java中的实现时没有任何变化。

这是我的XML工作表:

main_activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MyActivity">

    <fragment
        android:id="@+id/fragments"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.example.ilan.myapplication.fragments.FragmentHome" >
    </fragment>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Buffering"
        android:id="@+id/tV_Buffering"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true" />

    <include
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_weight="1"
        layout="@layout/player_controls"
        android:layout_alignParentBottom="true"/>

    <include
        layout="@layout/navigation_drawer_main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

请注意,我将导航抽屉放在最后,以使其涵盖所有活动。

navigation_drawer_main_layout.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#FFFFFF"/>
</android.support.v4.widget.DrawerLayout>

player_controls.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/blue">

        <Button
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:id="@+id/button_play_pause"
            android:layout_toStartOf="@+id/tV_Buffering"
            android:background="@drawable/bouton_play"
            android:layout_centerInParent="true"
           />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Stop"
            android:id="@+id/button_stop"
            android:layout_toRightOf="@id/button_play_pause"
            android:layout_centerInParent="true"
            android:layout_marginLeft="20dp"/>
</RelativeLayout>

好吧,如果有人对它的来源有任何想法,那就太好了,谢谢!

要使用DrawerLayout,请将主内容视图定位为第一个孩子,其宽度和高度为match_parent,而没有layout_gravity。 在主要内容视图之后添加抽屉作为子视图,并适当设置layout_gravity。 抽屉通常将match_parent用于具有固定宽度的高度。 查看有关DrawerLayout的Google文档: https : //developer.android.com/reference/android/support/v4/widget/DrawerLayout.html

您的主要内容应该放在DrawerLayout内,而不是在RelativeLayout内包含DrawerLayout。

对于您的情况,您可以尝试以这种方式实现它:

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MyActivity">

        <fragment
            android:id="@+id/fragments"
            class="com.example.ilan.myapplication.fragments.FragmentHome"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </fragment>


        <TextView
            android:id="@+id/tV_Buffering"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:text="Buffering"
            android:textAppearance="?android:attr/textAppearanceSmall"/>

        <include
            layout="@layout/player_controls"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_alignParentBottom="true"
            android:layout_weight="1"/>

    </RelativeLayout>

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#FFFFFF"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"/>
</android.support.v4.widget.DrawerLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM