[英]Navigation menu item “badge” vertically alignment
Hello I'm using badge counter in navigation menu, but. 您好我在导航菜单中使用徽章计数器,但是。 I can't move to center vertically. 我不能移动到垂直中心。 I tried margin, height:match_parent but width shape not success. 我尝试了margin,height:match_parent但宽度形状没有成功。
( https://stackoverflow.com/a/33607630/4933464 ) Here my codes ( I use with shape ): ( https://stackoverflow.com/a/33607630/4933464 )这里是我的代码(我使用的形状):
@drawable/menu_counter.xml @绘制/ menu_counter.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ec443e" />
<padding
android:left="5dp"
android:right="5dp"
android:top="3dp"
android:bottom="3dp"/>
<corners android:radius="5dp" />
</shape>
@layout/menu_counter.xml @布局/ menu_counter.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@drawable/menu_counter"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="#ffffff" />
Thanks. 谢谢。
Original DrawerLayout doesn't support badges. 原始DrawerLayout不支持徽章。 But there is a many useful library 但是有很多有用的库
MaterialDrawer : https://github.com/mikepenz/MaterialDrawer MaterialDrawer : https : //github.com/mikepenz/MaterialDrawer
Screenshots aviable on github page. 屏幕截图可在github页面上获得。
Wrap it with a relative layout and add 用相对布局包装并添加
android:layout_centerVertical="true" 机器人:layout_centerVertical = “真”
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerVertical="true"
android:background="@drawable/menu_counter"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="#ffffff" />
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.