Android圓形角標

2021-09-22 01:29:03 字數 2548 閱讀 2267

view**:

import android.content.context;

import android.content.res.typedarray;

import android.graphics.canvas;

import android.graphics.color;

import android.graphics.paint;

import android.graphics.rect;

import android.os.build;

import android.support.annotation.nullable;

import android.support.annotation.requiresapi;

import android.text.textutils;

import android.util.attributeset;

import android.util.log;

import android.view.view;

import com.xlkx.findreagent.r;

import com.xlkx.findreagent.utils.sizeutil;

public class circlenumberview extends view

private void initview()

//文字所佔的區域,用來確定文字的起始座標

rect rect = null;

if (rect == null)

paint.gettextbounds("99+", 0, "99+".length(), rect);

float viewwidth = rect.width();

float viewheight = rect.height();

if (viewwidth >= viewheight) else

log.e("開始測量時候的radius", radius + "");

}private void initatters(context context, @nullable attributeset attrs) else

}@override

protected void ondraw(canvas canvas)

if (integer.parseint(number) > 99) else

//為了讓文字縱向居中,計算正確的y值

paint.fontmetrics fontmetrics = paint1.getfontmetrics();

//ascent的絕對值=descent+2*(文字縱向中線與基準線的高度差)

//float baseline = 0;

=fontmetrics.descent+2*(baseline-height/2);

float y = radius / 2.0f + (math.abs(fontmetrics.ascent) - fontmetrics.descent) / 2.0f;

log.e("實際文字的寬度是", rect1.width() + "");

float startx = radius / 2.0f - rect1.width() / 2.0f;

startx = radius / 2.0f;

log.e("實際文字的startx是", startx + "");

if (integer.parseint(number) > 99) else

log.e("最後繪製的文字是", number);

}@override

protected void onmeasure(int widthmeasurespec, int heightmeasurespec)

public circlenumberview(context context)

public circlenumberview(context context, @nullable attributeset attrs)

public circlenumberview(context context, @nullable attributeset attrs, int defstyleattr)

@requiresapi(api = build.version_codes.lollipop)

public circlenumberview(context context, @nullable attributeset attrs, int defstyleattr, int defstyleres)

}atters**

<?xml version="1.0" encoding="utf-8"?>

使用樣例:

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginleft="10dp"

android:layout_torightof="@+id/button"

角點檢測,圓形檢測

角點檢測 圓檢測 已知直線方程斜截式表示式 y k x b r是從原點到直線的最短距離,為x軸與最短距離連線夾角。將k,b用r,關係替換,直線表示式為 對於任意一點 x,y 在hough變換中 對應一條曲線。多個點對應多條曲線,這些曲線有交點,交點處就是對應點組成的直線 如果有多個交點說明有多條直線...

Android定義圓形ProgressBar

我們以progressbarstylelarge為例進行探索,找到這個布局檔案,原始碼如下 同樣一眼看出 indeterminatedrawable 便是主角了,繼續看一下progress large white原始碼,如下 看到這裡就透徹了,就是在這裡spinner white 76進行不停的旋轉...

CSS 畫三角 扇形 圓形

元素為矩形,而它的每個border為乙個等腰梯形,上底為的width height,高為border的粗細。把四邊的上底設為0,即width 0,height 0 時,梯形就變成三角形了。dividerect 接著把四面的border中的兩條border變成transparent 透明,一條不定義,...