安卓导航抽屉菜单:如何可折叠导航项目 [英] Android: Navigation Drawer SubMenu: How to Collapsible navigation items
问题描述
我有一个抽屉式导航10选项 选项#5 shoudl有另外7个选项中某种即展开/可折叠的(如子菜单)
如何创建一个可折叠的导航项目就像是这里描述: <一href="http://developer.android.com/design/patterns/navigation-drawer.html#Content">http://developer.android.com/design/patterns/navigation-drawer.html#Content
下面是一个示例应用程序,这使得它:
@覆盖
公共查看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的&LT;字符串&GT;)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:
@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:
这篇关于安卓导航抽屉菜单:如何可折叠导航项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!