【问题标题】:How to set the badge position in tabs如何在标签中设置徽章位置
【发布时间】:2012-09-17 07:44:18
【问题描述】:

我对徽章的概念不熟悉。在我的应用程序中,我想在选项卡上显示徽章。为此,我使用了 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();

输出:

【问题讨论】:

  • 你如何解决这个错误,请指导我
  • 你如何对抗泡沫

标签: android badge


【解决方案1】:

默认位置是TOP_RIGHT。如果你想要任何其他位置,你必须设置它。 例如 对于 top_left 使用:

badge1.setBadgePosition(BadgeView.POSITION_TOP_LEFT);

供中心使用:

badge1.setBadgePosition(BadgeView.POSITION_CENTER);

对于bottom_left使用:

badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_LEFT);

对于右下角使用:

badge1.setBadgePosition(BadgeView.POSITION_BOTTOM_RIGHT);

【讨论】:

  • 这里 top_left 的工作方式类似于 bottom_left 和 top_right 的工作方式类似于 bottom_right。重置它们工作正常,为什么?底部标签栏有问题吗?在这里,对于每个选项卡,我设置了一个视图,该视图具有垂直顺序的图像和文本。
【解决方案2】:

要让徽章位置显示在选项卡的上角,您需要将选项卡布局的根设置为 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多