android实现抽屉效果图,android – 实现滚动导航抽屉的最佳方式

only the ListView scrolls, and the ImageView stays as it is

听起来您的抽屉在顶部包含一个ImageView,然后是ListView.使用此配置,只有ListView将滚动(因为它是唯一可滚动的视图).

您需要将ImageView添加为始终位于列表开头的标题.作为建议的评论之一,请执行listView.addHeaderView.

there seems to be a LinearLayout at the bottom of the navigation

drawer layout which I think is responsible for the list of items

shown. Could someone explain how this would work?

他们使用LinearLayout作为容器来容纳所有TextView:

private void createNavDrawerItems() {

mDrawerItemsListContainer = (ViewGroup) findViewById(R.id.navdrawer_items_list);

...

int i = 0;

for (int itemId : mNavDrawerItems) {

mNavDrawerItemViews[i] = makeNavDrawerItem(itemId, mDrawerItemsListContainer);

mDrawerItemsListContainer.addView(mNavDrawerItemViews[i]);

++i;

}

}

我相信他们使用LinearLayout并以编程方式对所有项目进行充气的原因是为了能够轻松地使用分隔符项:

private View makeNavDrawerItem(final int itemId, ViewGroup container) {

...

if (itemId == NAVDRAWER_ITEM_SEPARATOR) {

layoutToInflate = R.layout.navdrawer_separator;

} else if (itemId == NAVDRAWER_ITEM_SEPARATOR_SPECIAL) {

layoutToInflate = R.layout.navdrawer_separator;

} else {

layoutToInflate = R.layout.navdrawer_item;

}

...

return view;

}

在ListView中,您必须创建一个单独的项类型并在那里使用分隔符的布局,这可能会变得更加繁琐.

然而,乍一看,这段代码似乎正在重新发明轮子,因为使用ListView可以实现所有这一切.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值