Android 如何在选项卡中设置徽章位置

Android 如何在选项卡中设置徽章位置,android,badge,Android,Badge,我不熟悉badge的概念。在我的应用程序中,我想在标签上显示徽章。为此,我使用了android-viewbadger.jar文件。工作正常,但不影响位置属性。如何设置位置。如果你需要更多信息,请告诉我 TabWidget tabs = (TabWidget) findViewById(android.R.id.tabs); DH_Constant.badgeView = new BadgeView(this, tabs, 2); // it's working fine bad

我不熟悉badge的概念。在我的应用程序中,我想在标签上显示徽章。为此,我使用了android-viewbadger.jar文件。工作正常,但不影响位置属性。如何设置位置。如果你需要更多信息,请告诉我

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();
输出:


默认情况下,它的位置是
右上方
。如果你想要任何其他位置,你必须设置它。 例如 左上角使用:

badge1.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_LEFT);
供中心使用:

badge1.setBadgePosition(BadgeView.POSITION_CENTER);
对于左下角,请使用:

badge1.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_LEFT);
对于右下角的使用:

badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_RIGHT);

默认情况下,它的位置为
右上方
。如果你想要任何其他位置,你必须设置它。 例如 左上角使用:

badge1.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_LEFT);
供中心使用:

badge1.setBadgePosition(BadgeView.POSITION_CENTER);
对于左下角,请使用:

badge1.setBadgePosition(BadgeView.POSITION_TOP_LEFT);
badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_LEFT);
对于右下角的使用:

badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_RIGHT);

要使徽章位置显示在选项卡的上角,您需要将选项卡布局的根设置为FrameLayout,如下所示:

<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>


要在选项卡的上角显示徽章位置,需要将选项卡布局的根设置为FrameLayout,如下所示:

<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>


在这里,左上角与左下角类似,右上角与右下角类似。它们的重置工作正常为什么?底部选项卡栏有问题吗?在这里,我为每个选项卡设置一个视图,使图像和文本按垂直顺序排列。在这里,左上角与左下角相似,右上角与右下角相似。它们的重置工作正常为什么?底部选项卡栏有问题吗?在这里,我为每个选项卡设置了一个视图,使图像和文本按垂直顺序排列。你如何解决此错误?请你指导我如何解决气泡?你如何解决此错误?请你指导我如何解决气泡