android:基本活动上的按钮点击事件

时间:2015-01-30 22:03:20

标签: android android-layout android-activity android-button android-framelayout

我为我的应用程序中的所有活动和滑动菜单创建了相同布局的BaseActivity,我在基本活动布局中有一个按钮,我的问题是当我点击按钮时没有任何事情发生并且此消息显示在日志中:

D/VelocityTracker﹕ Couldn't open '/dev/touch' (Permission denied)
D/VelocityTracker﹕ tpd read x fail: Bad file number
D/VelocityTracker﹕ tpd read y fail: Bad file number
D/VelocityTracker﹕ Couldn't open '/dev/touch' (Permission denied)
D/VelocityTracker﹕ tpd read x fail: Bad file number
D/VelocityTracker﹕ tpd read y fail: Bad file number
I/View﹕ Touch down dispatch to android.widget.Button{424d3700 VFED..C. ........ 27,27-70,70 #7f070052 app:id/button_menu}, event = MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=27.332088, y[0]=3.7002335, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=182860652, downTime=182860652, deviceId=2, source=0x1002 }
I/View﹕ Touch up dispatch to android.widget.Button{424d3700 VFED..C. ...p.... 27,27-70,70 #7f070052 app:id/button_menu}, event = MotionEvent { action=ACTION_UP, id[0]=0, x[0]=24.136082, y[0]=3.7002335, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=182860725, downTime=182860652, deviceId=2, source=0x1002 }

这是我的基本活动布局:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- Put what you want as your normal screen in here, you can also choose for a linear layout or any other layout, whatever you prefer -->
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"
        android:id="@+id/sub_layout"
       >
        <Button
            android:id="@+id/button_menu"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/menu"
            android:text="Ok" />

    </RelativeLayout>
</FrameLayout>
<!-- The navigation drawer -->
<RelativeLayout
    android:id="@+id/left_drawer"
    android:layout_width="250dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp">
</RelativeLayout>

这是我的基本活动代码:

公共类BaseActivity扩展了Activity {

protected FrameLayout frameLayout;

protected RelativeLayout mDrawerList;


protected static int position;

private static boolean isLaunch = true;

protected DrawerLayout mDrawerLayout;

private ActionBarDrawerToggle actionBarDrawerToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_base);

    frameLayout = (FrameLayout) findViewById(R.id.content_frame);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (RelativeLayout) findViewById(R.id.left_drawer);



    Button btn_menu = (Button) findViewById(R.id.button_menu);
    btn_menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mDrawerLayout.openDrawer(mDrawerList);
            Log.d("Menu is open","???");
        }
    });


}

我不明白这是什么问题。 有谁能够帮我 ? 感谢

2 个答案:

答案 0 :(得分:1)

你的xml存在问题.. 您正在关闭一个不存在的RelativeLayout ..

<FrameLayout>
--- <RelativeLayout>
-------- <Button></Button>
--- </RelativeLayout>
--- </RelativeLayout> *THIS*
</FrameLayout>

答案 1 :(得分:1)

listview有一些错误点击相对布局,你必须添加一个名为android的属性:descendantFocusability =&#34; blocksDescendants&#34;解决..

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
..........
</RelativeLayout>

希望这会有所帮助..