我想要做一些从一开始我已经知道实现起来相当困难,并且在屏幕底部放置导航抽屉菜单的页脚。在屏幕底部设置Android导航抽屉菜单页脚
事实上,当抽屉的列表视图项目全部在屏幕上可见并且页脚应该位于最后一个项目下方时,我需要页脚完全位于屏幕的底部屏幕和滚动条出现(正常行为)。
对于我使用的是addFooterView方法在接下来的方式
ViewGroup footer = (ViewGroup)inflater.inflate(R.layout.testme_drawer_footer, mDrawerList, false);
mDrawerList.addFooterView(footer, null, false);
哪里testme_drawer_footer是下一个布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer_menu_facebook"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="start"
android:orientation="horizontal">
<TextView
android:id="@+id/drawer_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#8d3169"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#fff"
android:textSize="12sp"/>
</LinearLayout>
没有做任何事情的addFooterView只是表现正常的方式,如果元素全部在屏幕上可见,并且底部留下很多空白空间,页脚仅放置在最后一个元素下面(对于我试图达到的效果不好)。
我试着在徒劳无功地挣扎我的头一会儿我能得到的东西非常接近我后需要不同的StackOverflow的帖子很多建议,这是下一个:
我给所有的列表视图元素一个固定的高度和相同的标题所以最后我计算页脚高度与screenHeight - statusBarHeight - actionBarHeight - drawerHeaderHeight - listViewElementHeight * numberOfElements在接下来的方式:
ViewGroup footer = (ViewGroup)inflater.inflate(R.layout.testme_drawer_footer, mDrawerList, false);
int screenHeight = GeneralUtils.getScreenHeight(oActivity);
int statusBarHeight = GeneralUtils.getStatusBarHeight(oActivity);
int actionBarHeight = GeneralUtils.getActionBarHeight(oActivity);
int drawerHeaderHeight = GeneralUtils.dp2px(60, oActivity);
int menuItemHeight = drawerHeaderHeight;
int totalItemsHeight = menuItemHeight*(endItem-startItem+1);
int footerHeight = screenHeight - statusBarHeight - actionBarHeight - drawerHeaderHeight - totalItemsHeight;
footer.setMinimumHeight(footerHeight);
mDrawerList.setFooterDividersEnabled(true);
mDrawerList.addFooterView(footer, null, false);
但它是最有可能的一些的高度测量方法并不十分精确,有在所有测试过的设备中,某些像素的差异并不相同。
我知道这不是最好的办法,实际上我不喜欢它,我不喜欢为wrap_content设置固定高度的抽屉头和元素,我不喜欢计算整体高度这种方式,但无法找到任何其他工作方式来实现这一目标。
任何帮助?
在此先感谢!
这是我设置在所有活动中的ListView方式:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llMainMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="horizontal">
//MAIN CONTENT
<ListView
android:id="@+id/left_drawer"
android:layout_width="@dimen/navigation_drawer_width_phone"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:headerDividersEnabled="true"
android:background="#ffeeeeee"/>
</android.support.v4.widget.DrawerLayout>
这可能有帮助https:// stackoverflow。com/questions/30543605/how-to-add-footer-to-navigationview-android-support-design-library – seon
感谢您的回复和时间@seon,我终于解决了我的问题,就像我在下面描述的那样。 –