English 中文(简体)
无法单击滑动拖放器中的按钮
原标题:Could not click on the buttons in SlidingDrawer
  • 时间:2012-05-24 04:32:46
  •  标签:
  • android

我对滑动拖曳器有问题。 无法单击其中的所有按钮 。

这是我的滑动拖曳器的 xml 文件 :

<?xml version="1.0" encoding="utf-8"?>
<SlidingDrawer xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="110dp"
    android:content="@+id/content"
    android:handle="@+id/handle">

    <Button
        android:id="@+id/handle"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:text="@string/menu" />

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_gravity="center"
        >

        <Button
            android:id="@+id/btn_video"
            style="@style/button_menu_bottom"
            android:drawableTop="@drawable/mnu_video"
            android:text="@string/video" />

        ...
        ...

    </LinearLayout>

</SlidingDrawer>

这是我从SlidingDrawer扩展的 java 文件

包件 com. example;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.SlidingDrawer;
import com.example.R;

public class BottomMenuBar extends SlidingDrawer {

    private SlidingDrawer mSlidingDrawer;
    private Button mButtonSlidingDrawer;
    private LinearLayout mLayoutContent;
    private Button mButtonVideo;
    private Button mButtonPhoto;
    private Button mButtonChat;
    private Button mButtonSetting;

    public BottomMenuBar2(Context context, AttributeSet attrs) {
        super(context, attrs);
        String infService = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater li;
        li = (LayoutInflater) getContext().getSystemService(infService);
        li.inflate(R.layout.bar_bottom_menu, this, true);
        mSlidingDrawer=(SlidingDrawer)findViewById(R.id.sld_bottom_menu);
        mButtonSlidingDrawer=(Button)findViewById(R.id.handle);
        mLayoutContent=(LinearLayout)findViewById(R.id.content);
        mButtonVideo=(Button)findViewById(R.id.btn_video);
        mButtonSetting=(Button)findViewById(R.id.btn_setting);
    }

    public Button getmButtonSlidingDrawer() {
        return mButtonSlidingDrawer;
    }
    public void setmButtonSlidingDrawer(Button mButtonSlidingDrawer) {
        this.mButtonSlidingDrawer = mButtonSlidingDrawer;
    }

    ...
    Setter & Getter methods
    ...     
}

这是我的主. xml 文件 :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_main"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.1" >

        ...
        Any content
        ...

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <com.example.BottomMenuBar
            android:id="@+id/sld_bottom_menu"
            android:layout_width="wrap_content"
            android:layout_height="110dp"
            android:handle="@+id/handle"
            android:content="@+id/content"
            />

    </LinearLayout>

</LinearLayout>
问题回答

对于我在滑动抽屉中的按钮,我告诉每个按钮在 android: onClick xml xml 中使用什么方法 。

        <Button
            android:id="@+id/sortbutton"
            android:layout_width="0dp"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:onClick="SortClickHandler"
            android:text="@string/sd_sortmethod_button"
            android:textSize="12dp" />

然后界定任何适当活动的方法:

public void SortClickHandler(View v) {
    //  Do stuff here
}

<强 > EDIT

我想我找到了你的问题。从开发商的文档这里写着:

SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer 
should only be used inside of a FrameLayout or a RelativeLayout for instance.

所以,我想,如果你把布局改变为相对拉尤特, 你会发现你的按钮会起作用。 我只是重复检查了我对滑动抽屉的所有用途, 并且在所有情况中, 包含它的观点的根元素是相对拉尤特。

我不明白你为什么再扩展 SlidingDrawer

您应该查看文件 < a href="""http:// developmenter.android.com/ reference/android/widget/SlidingDrawer.html" rel="no follow" >这里

<SlidingDrawer
 android:id="@+id/drawer"
 android:layout_width="match_parent"
 android:layout_height="match_parent"

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

 <ImageView
     android:id="@id/handle"
     android:layout_width="88dip"
     android:layout_height="44dip" />

 <FrameView
     android:id="@id/content"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
   [INSERT VIEWS HERE]
 <FrameView>

</SlidingDrawer>

在您的 Actionience 中,您在技术上甚至不需要访问 SlidingDrawer 对象(滑动功能已经作为标准存在,它只是包含 content 中的视图,无需干涉)。

从您的 activity 获取引用到您在 [INSTERT VEWS here] 中添加的视图。 您可以在这些按钮中的每个按钮上做 set OnClickListener ()





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签