2014-03-26 6 views
2

I want to create the drawer exactly look like this서랍 내비게이션을 만드는 방법은 무엇입니까?

안녕하세요 여러분, 서랍 내비게이션을 만들고 싶습니다. 나는 몇 가지 문서를 읽었으나 일을하지 못했기 때문에 서랍 레이아웃을 이렇게 보이도록 그림을 보여줄 것이다. 당신이 나를 돕기 위해 어떤 것을 쓸 수 있기를 바랍니다 :)

+0

코드는 여기에 있습니다. http://stackoverflow.com/questions/17149776/android-navigation-drawer-submenu-how-to-collapsible-navigation-items –

답변

3

: here

NavigationDrawer : here

예 :

<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <!-- Content --> 
    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <!-- Menu right --> 
    <LinearLayout 
     android:id="@+id/menu_droite" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="#000000" 
     android:layout_gravity="end"> 

     <!-- Liste du menu droite --> 
     <ExpandableListView 
      android:id="@+id/right_drawer" 
      android:layout_width="match_parent" 
      android:layout_height="480dp" 
      android:choiceMode="singleChoice" 
      android:listSelector="#037DA6" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="0dp" 
      android:background="#111" 
      android:groupIndicator="@drawable/group_indicator" 
      /> 

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

ExpandableListAdapter.java :

import java.util.HashMap; 
import java.util.List; 

import android.content.Context; 
import android.graphics.Typeface; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseExpandableListAdapter; 
import android.widget.TextView; 

public class ExpandableListAdapter extends BaseExpandableListAdapter { 

    private Context _context; 
    private List<String> _listDataHeader; 
    private HashMap<String, List<String>> _listDataChild; 

    public ExpandableListAdapter(Context context, List<String> listDataHeader, 
      HashMap<String, List<String>> listChildData) { 
     this._context = context; 
     this._listDataHeader = listDataHeader; 
     this._listDataChild = listChildData; 
    } 

    @Override 
    public Object getChild(int groupPosition, int childPosititon) { 
     return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
       .get(childPosititon); 
    } 

    @Override 
    public long getChildId(int groupPosition, int childPosition) { 
     return childPosition; 
    } 

    @Override 
    public View getChildView(int groupPosition, final int childPosition, 
      boolean isLastChild, View convertView, ViewGroup parent) { 

     final String childText = (String) getChild(groupPosition, childPosition); 

     if (convertView == null) { 
      LayoutInflater infalInflater = (LayoutInflater) this._context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.list_item, null); 
     } 

     TextView txtListChild = (TextView) convertView 
       .findViewById(R.id.lblListItem); 

     txtListChild.setText(childText); 
     return convertView; 
    } 

    @Override 
    public int getChildrenCount(int groupPosition) { 
     return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
       .size(); 
    } 

    @Override 
    public Object getGroup(int groupPosition) { 
     return this._listDataHeader.get(groupPosition); 
    } 

    @Override 
    public int getGroupCount() { 
     return this._listDataHeader.size(); 
    } 

    @Override 
    public long getGroupId(int groupPosition) { 
     return groupPosition; 
    } 

    @Override 
    public View getGroupView(int groupPosition, boolean isExpanded, 
      View convertView, ViewGroup parent) { 
     String headerTitle = (String) getGroup(groupPosition); 
     if (convertView == null) { 
      LayoutInflater infalInflater = (LayoutInflater) this._context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.list_group, null); 
     } 

     TextView lblListHeader = (TextView) convertView 
       .findViewById(R.id.lblListHeader); 
     lblListHeader.setTypeface(null, Typeface.NORMAL); 
     lblListHeader.setText(headerTitle); 

     return convertView; 
    } 

    @Override 
    public boolean hasStableIds() { 
     return false; 
    } 

    @Override 
    public boolean isChildSelectable(int groupPosition, int childPosition) { 
     return true; 
    } 
} 
1

여기에 문서 탐색기 : https://developer.android.com/training/implementing-navigation/nav-drawer.html 당신은 자신의 레이아웃을 만들어 거기에 ExpandableListView를 두어야합니다. 목록 항목에는 이러한 파란색 카운터에 대한 사용자 지정 레이아웃이 있어야합니다.

P. 오른쪽 상단의 아이콘은 탐색 메뉴가 아닌 시작 메뉴 용 아이콘입니다. 서랍을 열려면 앱 아이콘을 터치해야합니다. 가이드 라인을 참조하십시오.

당신은 당신의 NavigationDrawer

ExpandableListView에 ExpandableListView을해야