19

我有一个带有 10 个选项的导航抽屉 选项 #5 应该有另外 7 个可扩展/可折叠的选项(如子菜单)

如何创建此处描述的“可折叠导航项” ?

4

1 回答 1

17

这是一个示例应用程序:

PrashamTrivedi / DrawerLayoutTest:链接已失效

编辑:Android 中的简单导航抽屉布局

@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;
}

您必须在布局文件夹中创建新的 xml 文件(提示:创建两个,一个用于组视图,另一个用于子菜单)

毕竟,您的侧边导航必须如下所示:

在此处输入图像描述

于 2014-02-16T12:55:25.507 回答