2015-10-16 2 views
0

У меня есть действие, которое отображает макет ящика при щелчке элемента меню, поэтому его направление направо налево. Мне удается отобразить меню навигации, используя следующий код.Не удалось щелкнуть справа налево Элементы 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); 

    } 

Мой навигации ящик содержит статический список, так что я не удосужился сделать ListView из него, как показано ниже,

enter image description here

Однако я не могу нажать мои пункты внутри макета ящика, или что-либо в представлении даже v4.widget.DrawerLayout в моем xml не имеет значения. Ниже приведен два файла 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, но вместо этого я до сих пор не везёт .. пожалуйста помощь, Im новый при использовании схемы выдвижного ящика, поэтому может возникнуть еще кое-что, что мне нужно знать .. Спасибо заранее.

ответ

0

Для предотвращения возврата OnClickListener к исходной макету необходимо установить android:clickable="true" в контейнер для контейнера.

<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> 

в вашей деятельности

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 >>>>>>>>>>>>>>>>>>"); 
     } 
    }); 

    } 
}