我正在尝试显示按钮右上角的通知数量,我正在使用ViewBadger(外部库:android-viewbadger http://jgilfelt.github.io/android-viewbadger)。我现在面临的问题是徽章显示在按钮背面,如此
但我想在Facebook或任何其他应用程序前面显示徽章
这是我的代码
package com.daimkhan.badgerview;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.readystatesoftware.viewbadger.BadgeView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View button = findViewById(R.id.button);
final BadgeView badge = new BadgeView(this, button);
badge.setText("8");
badge.setTextSize(12);
badge.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
badge.setBadgeMargin(0, 0);
badge.show();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
badge.hide();
}
});
}
}
请提前帮助我,谢谢:)
答案 0 :(得分:1)
在显示徽章
之前尝试此操作ViewCompat.setTranslationZ(badge, 10);
这会改变视图相对于Z轴的高程。
官方文件说
setTranslationZ
void setTranslationZ (View view, float translationZ)
Sets the depth location of this view relative to its elevation.
答案 1 :(得分:0)
它适用于我,使用您提供的相同代码;
尝试将此作为您的布局文件(可能问题在于您的布局):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"/>
</RelativeLayout>
答案 2 :(得分:-1)