相对布局中的OnClick for Drawer不起作用

时间:2015-07-15 06:52:28

标签: android android-listview slidingdrawer drawerlayout

我有一个带抽屉的布局 选项卡3中有3个选项卡我需要将布局看起来与此类似! Image 1

现在,当我尝试点击抽屉中的任何项目时,<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:background="@color/blue_end_grdeient" android:layout_height="match_parent" tools:context=".MainActivity" android:descendantFocusability="blocksDescendants" > <!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="blocksDescendants" /> <!-- The navigation drawer --> <LinearLayout android:id="@+id/drawer" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/blue_end_grdeient" android:gravity="center_horizontal" android:orientation="vertical" android:descendantFocusability="blocksDescendants"> <ListView android:id="@+id/left_drawer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" android:background="@color/blue_end_grdeient" android:choiceMode="singleChoice" android:divider="@color/grey" android:dividerHeight="1dp" android:descendantFocusability="blocksDescendants"/> </LinearLayout> <RelativeLayout android:id="@+id/helpview" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="visible" android:background="#80000000" android:alpha="0.9"> <Button android:id="@+id/invisible_button" style="@color/blue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="Ok! Got it !" android:visibility="invisible" android:textColor="#FFFFFF" /> <ImageButton android:id="@+id/dummy" android:layout_width="@dimen/fab_button_diameter" android:layout_height="@dimen/fab_button_diameter" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_marginBottom="@dimen/fab_button_margin_bottom" android:layout_marginRight="@dimen/fab_button_margin_right" android:background="@drawable/fab_shape" android:src="@drawable/fab_ic_add" android:tint="@android:color/white" android:visibility="invisible" android:clickable="false" /> <ImageView android:id="@+id/downButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/dummy" android:layout_alignRight="@+id/dummy" android:layout_marginRight="15dp" android:src="@drawable/arrow1_bottom" /> <TextView android:id="@+id/addMemberTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/downButton" android:layout_centerHorizontal="true" android:text="Click here to Add New Members" android:textAppearance="?android:attr/textAppearanceMedium" /> <Button android:id="@+id/next1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/dummy" android:layout_centerHorizontal="true" android:layout_marginBottom="13dp" android:background="@color/new_orange" android:paddingLeft="10dp" android:paddingRight="10dp" android:text="Ok, Got it!" android:focusable="false"/> <ImageView android:id="@+id/ic_dots_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:visibility="invisible" android:src="@drawable/ic_dots_vertical" /> <TextView android:id="@+id/syncTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/arrow_top" android:layout_centerHorizontal="true" android:layout_marginTop="18dp" android:text="Click here to SYNC data with server" android:textAppearance="?android:attr/textAppearanceMedium" /> <ImageView android:id="@+id/arrow_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginRight="15dp" android:layout_toLeftOf="@+id/ic_dots_vertical" android:src="@drawable/arrow1_top" /> </RelativeLayout> 无效

我的XML代码

public void OnActionBarChanged(String mType) {

    if(mType.equals("2"))
    {
        setActionBarMembers();
        shared_preference = PreferenceManager.getDefaultSharedPreferences(this);
        String mFirstTiem = shared_preference.getString("FIRST_TIME_HELP",
                "null");
        if (mFirstTiem.equalsIgnoreCase("null")) {
            helpview.setVisibility(View.VISIBLE);
            next.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    helpview.setVisibility(View.GONE);
                    SharedPreferences.Editor editor = shared_preference.edit();
                    editor.putString("FIRST_TIME_HELP", "DONE");
                    editor.commit();
                }
            });
        }


    }
    else
    {
        setActionBar();
        helpview.setVisibility(View.GONE);

    }
    // TODO Auto-generated method stub

}

我显示此图片的代码

private class DrawerItemClickListener implements
        ListView.OnItemClickListener {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        selectItem(position);
    }
}
public void selectItem(int position) {
    // update the main content by replacing fragments

    // Bundle args = new Bundle();
    // args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    // fragment.setArguments(args);

    FragmentManager fragmentManager = getSupportFragmentManager();
    if (position == 0) {

        Intent mStart = new Intent(this, ProfileView.class);
        startActivity(mStart);

    } else if (position == 1) {

        Intent mStart = new Intent(this, SettingsView.class);
        startActivity(mStart);
    }

    else if (position == 2) {
        // Toast.makeText(MainActivity.this, "Work In Progress",
        // Toast.LENGTH_SHORT).show();
        Intent mStart = new Intent(this, HowToUseActivity.class);
        mStart.putExtra("type", "Help");

        startActivity(mStart);
    }
     else if (position == 3) {
            Intent mProcess = new Intent(this, MemberShipProcess.class);
            startActivity(mProcess);
        }

    else if (position == 4) {
        Intent mStart = new Intent(this, HowToUseActivity.class);
        mStart.putExtra("type", "FAQ");
        startActivity(mStart);
    }

    else if (position == 5) {
        Intent mStart = new Intent(this, NeedHelp.class);
        startActivity(mStart);
    }

    else if (position == 6) {
        Intent mStart = new Intent(this, AboutThisApp.class);
        startActivity(mStart);
    }

    mDrawerLayout.closeDrawers();

抽屉列表的代码是

{{1}}

1 个答案:

答案 0 :(得分:1)

您是否尝试过将ListView及其父布局(“抽屉”)点击?

android:clickable="true"