How to set the badge position in tabs

百般思念 提交于 2020-01-03 05:12:07

问题


I am new to badge's concept. In my application i want to show the badges on the tabs. For that i used the android-viewbadger.jar file. It's working fine but position property is not effected. How to set the position. If you need more info please let me know.

TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs);       
DH_Constant.badgeView = new BadgeView(this, tabs, 2);

// it's working fine

badge1.setBadgePosition(BadgeView.POSITION_CENTER);

// But I Supposed to set it as position to top_left or top_right then it still shows as bottom_left and bottom_right

badge1.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);

DH_Constant.badgeView.setText(DH_Constant.MessagesCount_obj.count); 
DH_Constant.badgeView.show();

Output:


回答1:


By default it's position is TOP_RIGHT. If you want any other position you have to set that. e.g For top_left use:

badge1.setBadgePosition(BadgeView.POSITION_TOP_LEFT);

For center use:

badge1.setBadgePosition(BadgeView.POSITION_CENTER);

For bottom_left use:

badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_LEFT);

For bottom_right use:

badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_RIGHT);



回答2:


To get badge position to show in top corner of your tab you need to set the root of your tab layout to FrameLayout like so:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout 
    android:id="@+id/tabsLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/tabs_background"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dip" >

    <ImageView
        android:id="@+id/tabsIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/tab_icon"
        android:duplicateParentState="true" />

    <TextView
        android:id="@+id/tabsText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/tabs_text"
        android:textSize="10dip"
        android:textStyle="bold" />

</LinearLayout>



来源:https://stackoverflow.com/questions/12455015/how-to-set-the-badge-position-in-tabs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!