的Android SlidingDrawer不“下”抽屉

问题描述:

这是该方案禁用按钮。 当我拉出屏幕并触摸B用来可见的屏幕时,其操作仍然执行。的Android SlidingDrawer不“下”抽屉

我该如何解决这个问题?

我发现this线程描述非常相同的问题,但没有答案被接受和那些给予我没能获得工作。

更新:我有一个名为Report.java文件,相应地report.xml将文件,如下图所示。

<SlidingDrawer 
    android:id="@+id/drawer" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:handle="@+id/reportSlideButton" 
    android:content="@+id/reportContent" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:id="@id/reportContent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:layout_weight="1" 
     android:padding="10dp" 
     android:background="@color/bg_color"> 
      <TextView android:id="@+id/garbageTypeTextView" 
       android:layout_height="wrap_content" 
       android:textColor="@color/text" 
       android:layout_width="fill_parent" 
       android:text="@string/garbageTypeString" 
       android:textStyle="bold"/> 
      <Spinner android:id="@+id/garbageTypeSpinner" 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent"/> 
      <TextView android:id="@+id/textViewForDateTitle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/dateString" 
       android:textColor="@color/text" 
       android:textStyle="bold" /> 
      <TextView android:id="@+id/dateTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/text" /> 
      <TextView android:id="@+id/textViewForAddressTitle" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="@string/addressString" 
       android:textColor="@color/text" 
       android:textStyle="bold" /> 
      <TextView android:id="@+id/addressTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/text" /> 
      <TextView android:id="@+id/textViewForPositionTitle" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="@string/positionString" 
       android:textColor="@color/text" 
       android:textStyle="bold" /> 
      <TextView android:id="@+id/positionTextView" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textColor="@color/text" /> 
      <TextView android:id="@+id/textViewForCommentTitle" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="@string/commentString" 
       android:textColor="@color/text" 
       android:textStyle="bold" /> 
      <EditText android:id="@+id/commentTextBox" 
       android:layout_height="fill_parent" 
       android:layout_width="fill_parent" 
       android:layout_weight="1"/> 
      <Button android:id="@+id/sendCrapportButton" 
       android:onClick="sendCrapport" 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:text="Skicka rapport" /> 

    </LinearLayout> 
     <Button android:id="@id/reportSlideButton" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:text=">"/> 
</SlidingDrawer> 

添加组件:

protected void addComponents() { 
    takePictureButton = (ImageButton) findViewById(R.id.takePictureButton); 
    slidingDrawer = (SlidingDrawer) findViewById(R.id.drawer); 
} 

你可以添加机器人:可点击= “true” 以你的滑块内容标签(ID reportContent)。这样它不会“点击”。你的滑块内的按钮应该仍然工作..我希望;)

+2

如果您包含来自不同文件的布局(与我一样),则必须将android:clickable =“true”“'放入包含的布局文件中,而不要放在include标签中。让我用一个例子: – RichardB 2011-10-02 13:51:25

+0

邑,这是做到了。我的情况:将抽屉滑过回收站视图。使用 .setclickable();启用或禁用底下的视图。 – Nactus 2016-01-28 15:39:50

我想你应该在滑块平添一份监听器,并在它返回true。 这样,您将告诉系统触摸事件已被消耗。

+0

感谢您的答复。如果可以的话,请参阅我的评论。 – 2011-03-22 15:28:21

+1

后你得滑块上的参考,增加您的onCreate()方法:slider.setOnTouchListener(新OnTouchListener(){\t \t \t \t \t \t @覆盖 \t \t \t公共布尔onTouch(查看arg0中,MotionEvent ARG1){ \t \t \t \t \t \t \t回归真实; \t \t \t} \t \t}); – 2011-03-22 15:50:30

在您SlidingDrawer,覆盖onTouch(视图V,MotionEvent事件),并返回true。

有一件事我不清楚的是框架是否会考虑覆盖,即使它被关闭查看抽屉。如果是这种情况,那么您应该添加一些检查来查看抽屉的状态,并返回isOpened(),当抽屉打开时它将为true,当抽屉关闭时为false。

+0

我的问题是,我不知道如何调用我的SlidingDrawer上的方法,因为我没有这样的方法,只要我可以告诉我的Report.java类。你能否详细说明这将如何实施?我会在Report.java类中编写onTouch方法,并传递一个由SlidingDrawer拥有的视图或其他东西吗? – 2011-03-22 15:27:27

+0

现在把组件添加到程序中,但问题是当我使用findViewById实例化SlidingDrawer时,我可以重写onTouch方法。 – 2011-03-22 15:39:56

我有同样的问题。我的滑动抽屉里的物品无法获得焦点。在尝试了几个不同的事情之后,我发现我已经放置在标签和具有contentLayout的线性布局之间的滑动抽屉中。

一旦我删除它,一切工作正常。

<SlidingDrawer ....> 
    <FrameLayout android:id="@+id/slideHandle" ... /> 

     **MOVED** <ScrollView> **TO** 
    <LinearLayout android:id="@+id/contentLayout" ... > 
     <ScrollView> **HERE** 

我希望这有助于某人。

只是增加@ F-喇叭的回答是:

如果包括从不同的文件布局(像我一样)的SlidingDrawer,你必须把'机器人:可点击=‘真’ '在包含的布局文件中,而不是在包含标签中。让我宁愿用一个例子:

这是行不通的:

main.xml中

<SlidingDrawer android:handle="@+id/handle" 
     android:content="@+id/content"> 

     <ImageView android:id="@id/handle" /> 
     <include android:id="@+id/content" layout="@layout/some_other_layout" 
     android:clickable="true"/> 
</SlidingDrawer>' 

这将:

main.xml中

<SlidingDrawer android:handle="@+id/handle" 
     android:content="@+id/content"> 

     <ImageView android:id="@id/handle" /> 
     <include android:id="@+id/content" layout="@layout/some_other_layout"/> 
</SlidingDrawer>' 

some_ot her_layout。XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:clickable="true"> ............ 
<LinearLayout/> 

哎我还是坚持了这个错误的天,以便有简单的答案

你已经在你的类创建的slidingdrawer什么; 只是实现类,OnDrawerOpenListener,onDrawerCloseListener

然后让类中添加未实现的方法,并转到ondraweropenlistener{ slidingdrawer.setclickable(true); }

,并在drawercloselistener{ slidingdrawer.setclickable(false); }

这将设置当抽屉被打开将使它可点击并防止点击后面的视图,当它关闭时,每件事回到默认状态

这是最简单的解决方案尝试它:D

This is My main layout and where i introduce sliding drawer inside this. 

<?xml version="1.0" encoding="utf-8"?> 
    <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" 
    android:background="@color/Beige" 
    android:clickable="true" 
    android:orientation="vertical" > 

    <Button 
    android:id="@+id/DoneStart" 
    android:layout_width="100dp" 
    android:layout_height="40dp" 
    android:textSize="14sp" /> 

    <SlidingDrawer 
    android:id="@+id/SlidingDrawer" 
    android:layout_width="wrap_content" 
    android:layout_height="100dp" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:content="@+id/contentLayout" 
    android:handle="@+id/handle_image" 
    android:padding="1dp" 
    android:rotation="180" > 

    <LinearLayout 
    android:id="@+id/contentLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
    android:id="@+id/TextView01" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_weight="8" 
    android:text="Hello Slider" /> 
    </LinearLayout> 
    </SlidingDrawer> 

位挫折后我的样品在哪里添加机器人:可点击=“真”