无法单击从右到左的DrawerLayout项目

时间:2015-10-16 06:59:59

标签: android xml listview drawerlayout

我有一个活动,当点击菜单项时显示抽屉布局,因此它的方向是从右到左。我设法使用以下代码显示导航菜单。

public class Forecast_details extends ActionBarActivity implements OnChartValueSelectedListener {

....
 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        //return false;
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.

        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }

        if(id==R.id.Options){

            if (mDrawerlayout.isDrawerOpen(Gravity.END)){
                   mDrawerlayout.closeDrawer(Gravity.END);

               }else
                   mDrawerlayout.openDrawer(Gravity.END);

        }
        return super.onOptionsItemSelected(item);

    }

我的导航抽屉包含一个静态列表,所以我没有费心去制作一个列表视图,如下所示,

enter image description here

但是我无法在抽屉布局中单击我的项目,或者视图中的任何内容,即使我的xml中的v4.widget.DrawerLayout也是不可点击的。下面是我使用的两个xml文件。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <include
        android:id="@+id/tool_bar"
        layout="@layout/tool_bar"
        ></include>
       <android.support.v4.widget.DrawerLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/drawer_layout_right"
            android:layout_gravity="end"
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
            android:clickable="true">

           <include layout="@layout/nav_drawer_right" />

            <ScrollView
                android:id="@+id/scrollView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2.36" >

             ....

                </LinearLayout>
            </ScrollView>
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

nav_drawer_right.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView_right"
    android:layout_width="100dp"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:background="#2c3e50"
    android:paddingTop="20dp" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/container_fragment2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginTop="1dp" >

        </FrameLayout>

            <LinearLayout
                android:id="@+id/linearLayout_menuconatiner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:clickable="true"
                android:orientation="vertical"
                android:paddingLeft="2dp"
                android:paddingRight="2dp" >

                <ImageView
                    android:id="@+id/imageView_forward"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@color/darkblue"
                    android:clickable="true"
                    android:onClick="SendClick"
                    android:padding="5dp"
                    android:scaleType="fitCenter"
                    android:src="@drawable/ic_forward" />

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="3dip"
                    android:background="@color/separatorcolor"
                    android:paddingLeft="2dp"
                    android:paddingRight="2dp" />

                <ImageView
                    android:id="@+id/imageView_request"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@color/darkblue"
                    android:padding="5dp"
                    android:src="@drawable/ic_request" />

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="3dip"
                    android:background="@color/separatorcolor"
                    android:paddingLeft="2dp"
                    android:paddingRight="2dp" />

                <ImageView
                    android:id="@+id/imageView_reloadvnet"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@color/darkblue"
                    android:padding="5dp"
                    android:src="@drawable/ic_updatevnet" />

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="3dip"
                    android:background="@color/separatorcolor"
                    android:paddingLeft="2dp"
                    android:paddingRight="2dp" />

                <ImageView
                    android:id="@+id/imageView_reloadvsms"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@color/darkblue"
                    android:padding="5dp"
                    android:src="@drawable/ic_updatevsms" />

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="3dip"
                    android:background="@color/separatorcolor"
                    android:paddingLeft="2dp"
                    android:paddingRight="2dp" />

                <ImageView
                    android:id="@+id/imageView_feedback"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@color/darkblue"
                    android:padding="5dp"
                    android:src="@drawable/ic_feedback" />

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="3dip"
                    android:background="@color/separatorcolor"
                    android:paddingLeft="2dp"
                    android:paddingRight="2dp" />

            </LinearLayout>
        </RelativeLayout>


</ScrollView>

请帮助..我尝试了很多东西让它像使用listview一样工作,但我仍然没有运气..请帮忙,我是新的使用抽屉布局所以可能还有一些我需要的东西知道..提前谢谢..

1 个答案:

答案 0 :(得分:0)

To prevent return OnClickListener to parent layout require set android:clickable="true" in drawerLayout container. <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout_right" android:layout_gravity="end" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="2.36" > .... </ScrollView> <include layout="@layout/nav_drawer_right" /> </android.support.v4.widget.DrawerLayout> nav_drawer_right.xml <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView_right" android:layout_width="100dp" android:layout_height="match_parent" android:layout_gravity="end" android:background="#2c3e50" android:paddingTop="20dp" > .... </ScrollView> in your Activity public class MainActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); DrawerLayout mDrawerLayout= (DrawerLayout) findViewById(R.id.drawer_layout_right); ScrollView sV = (ScrollView) findViewById(R.id.scrollView1); mDrawerLayout.openDrawer(Gravity.RIGHT); sV.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.out.println("drawer click >>>>>>>>>>>>>>>>>>"); } }); } }