This commit is contained in:
huangjian
2023-03-21 19:27:41 +08:00
parent a8b993572c
commit bd14980c14
24 changed files with 162 additions and 68 deletions

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:bottomLeftRadius="16dp"
android:bottomRightRadius="16dp"
android:topLeftRadius="4dp"
android:topRightRadius="16dp"/>
<solid android:color="@color/white"/>
</shape>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding
android:left="15dp"
android:top="13dp"
android:right="15dp"
android:bottom="13dp" />
<solid android:color="#FFFCEBCA"/>
</shape>

View File

@@ -49,12 +49,11 @@ public class BubbleView extends AppCompatTextView {
setTextColor(ContextCompat.getColor(getContext(), R.color.white));
setTextSize(10);
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setShape(GradientDrawable.RECTANGLE);
gradientDrawable.setShape(GradientDrawable.OVAL);
// gradientDrawable.setShape(GradientDrawable.RECTANGLE);
gradientDrawable.setCornerRadius(ScreenUtil.dip2px(20));
gradientDrawable.setColor(Color.parseColor("#FF3B30"));
setBackground(gradientDrawable);
setPadding(ScreenUtil.dip2px(4), ScreenUtil.dip2px(1), ScreenUtil.dip2px(4), ScreenUtil.dip2px(1));
setGravity(Gravity.CENTER);
// TextViewCompat.setAutoSizeTextTypeWithDefaults(this,TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
// TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(this,
@@ -74,38 +73,22 @@ public class BubbleView extends AppCompatTextView {
* @param num
*/
public void setNumText(int num) {
// num += 100;
if (num < 1) {
setVisibility(GONE);
return;
}
setVisibility(VISIBLE);
String numStr;
if (num > 99) {
numStr = "99+";
numStr = "99";
} else {
numStr = String.valueOf(num);
}
getPaint().getTextBounds(numStr, 0, numStr.length(), textRect);
int width = textRect.width() + getPaddingStart() + getPaddingEnd();
int height = textRect.height() + getPaddingTop() + getPaddingBottom();
ViewGroup.LayoutParams lp = getLayoutParams();
lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
// if (num < 10) {
// int size = Math.max(width, height);
//// lp.width = size;
//// lp.height = size;
// lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
// lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
// } else {
// lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
// lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
// }
lp.width = ScreenUtil.dip2px(18);
lp.height = ScreenUtil.dip2px(18);
setLayoutParams(lp);
setText(numStr);
}
}