安卓导航抽屉菜单:如何可​​折叠导航项目抽屉、菜单、项目、何可

2023-09-12 23:06:03 作者:(_ъíе放棄,儍瓜

我有一个抽屉式导航10选项 选项​​#5 shoudl有另外7个选项中某种即展开/可折叠的(如子菜单)

如何创建一个可折叠的导航项目就像是这里描述: http://developer.android.com/design/patterns/navigation-drawer.html#Content

解决方案

下面是一个示例应用程序,这使得它:

  

PrashamTrivedi / DrawerLayoutTest

  @覆盖
    公共查看getGroupView(INT groupPosition,布尔isExpanded,查看convertView,父母的ViewGroup)
    {
        如果(convertView == NULL)
        {
            LayoutInflater layoutInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.drawer_group_item,父母,假);
        }

        ((TextView中)convertView).setText(groupItem.get(groupPosition));
        convertView.setTag(groupItem.get(groupPosition));
        返回convertView;
    }
 

  @覆盖
    公共查看getChildView(INT groupPosition,最终诠释childPosition,布尔isLastChild,查看convertView,父母的ViewGroup)
    {
        tempChild =(ArrayList的<字符串>)children.get(groupPosition);
        TextView的文本= NULL;

        如果(convertView == NULL)
        {
            LayoutInflater layoutInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.drawer_submenu_item,父母,假);
        }

        文=(TextView的)convertView;
        text.setText(tempChild.get(childPosition));

        convertView.setTag(tempChild.get(childPosition));
        返回convertView;
}
 

而你必须创建布局文件夹中的新的XML文件(提示的:创建两种,一种为组视图和其他的子菜单)

所有经过你身边的导航必须看起来像如下:

I have a Navigation Drawer with 10 options Option #5 shoudl have another 7 options (like a sub menu) of some sort that is expandable/collapsible

How do I create a "Collapsible navigation items" like it is described here: http://developer.android.com/design/patterns/navigation-drawer.html#Content

解决方案

Here is a sample application which makes it:

PrashamTrivedi / DrawerLayoutTest

@Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
    {
        if (convertView == null)
        {
            LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.drawer_group_item,parent,false);
        }

        ((TextView) convertView).setText(groupItem.get(groupPosition));
        convertView.setTag(groupItem.get(groupPosition));
        return convertView;
    }

@Override
    public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
    {
        tempChild = (ArrayList<String>) children.get(groupPosition);
        TextView text = null;

        if (convertView == null)
        {
            LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.drawer_submenu_item,parent,false);
        }

        text = (TextView) convertView;
        text.setText(tempChild.get(childPosition));

        convertView.setTag(tempChild.get(childPosition));
        return convertView;
}

And you have to create the new xml files in the layout folder (hint: create two, one for the group view and other for the submenu)

After all your side navigation must look like as below:

 
精彩推荐
图片推荐