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可以实现所有这一切.