国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 實現帶角標的ImageView(微博,QQ消息提示)

2019-10-22 18:16:53
字體:
來源:轉載
供稿:網友

角標繪制過程:用畫筆量出一個字符的寬度作為角標背景的半徑(R),然后判斷傳入字符串的總長度

如果只有一位字符:那么就以 R 為半徑,畫一個圓,然后在圓中寫上數字

如果有兩位以上的字符,就不能單純用一個圓了,用畫筆測量字符串的完整長度( len ),然后在右上角畫一個圓,在這個圓的圓心左邊 len 長度的位置 作為圓心再畫一個圓,最后以這個兩個圓的上下頂點(一共四個)構成一個矩形,進行填充

源碼地址:https://github.com/SiKang123/AndroidToolBox

效果如下:

Android,角標,ImageView,微博,QQ消息提示

集成方法

在Project的 build.gradle 下添加

allprojects {  repositories {    ...    maven { url 'https://jitpack.io' }  }}

在Module的 build.gradle 下添加

dependencies {    compile 'com.github.SiKang123:AndroidToolBox:1.0'}

使用方法

圖片中的效果,Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:app="http://schemas.android.com/apk/res-auto"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:gravity="center_horizontal"  android:orientation="vertical"  android:paddingTop="50dp">  <android.simple.toolbox.widget.CornerImageView    android:layout_width="50dp"    android:layout_height="50dp"    android:layout_margin="20dp"    android:src="@mipmap/ic_launcher"    app:cornerBackground="@color/red"    app:cornerText="9"    app:cornerTextColor="@color/white"    app:cornerTextSize="11dp" />  <android.simple.toolbox.widget.CornerImageView    android:layout_width="50dp"    android:layout_height="50dp"    android:layout_margin="20dp"    android:src="@mipmap/ic_launcher"    app:cornerBackground="@color/red"    app:cornerText="99"    app:cornerTextColor="@color/white"    app:cornerTextSize="11dp" />  <android.simple.toolbox.widget.CornerImageView    android:layout_width="50dp"    android:layout_height="50dp"    android:layout_margin="20dp"    android:src="@mipmap/ic_launcher"    app:cornerBackground="@color/red"    app:cornerText="999"    app:cornerTextColor="@color/white"    app:cornerTextSize="11dp" />  <android.simple.toolbox.widget.CornerImageView    android:id="@+id/progress_imageview"    android:layout_width="60dp"    android:layout_height="60dp"    android:layout_margin="20dp"    android:src="@mipmap/ic_launcher"    app:cornerBackground="@mipmap/shanchu"    app:cornerLoadColor="@color/alpha_black_35"    app:cornerRadius="7dp" /></LinearLayout>

Activtiy:

@Override  protected void onCreate(@Nullable Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_cornerimage);    //設置最后一個圖片的加載進度為20%,并添加點擊事件    CornerImageView imageView = (CornerImageView) findViewById(R.id.progress_imageview);    imageView.progress(20);    imageView.setOnCornerClickListener(new CornerImageView.OnCornerClickListener() {      @Override      public void onCornerClickListener(View view) {        Toast.makeText(SimpleCornerImageActivity.this, "角標被點擊", Toast.LENGTH_SHORT).show();      }    });  }

以上這篇Android 實現帶角標的ImageView(微博,QQ消息提示)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 无极县| 噶尔县| 石家庄市| 英超| 牟定县| 安塞县| 财经| 鄱阳县| 罗平县| 关岭| 沛县| 榆社县| 宁海县| 宿迁市| 山阴县| 辽宁省| 河池市| 泾川县| 德昌县| 平和县| 广平县| 扶绥县| 阿图什市| 荆州市| 平凉市| 乌拉特后旗| 龙游县| 稻城县| 陇西县| 武城县| 栖霞市| 绩溪县| 灯塔市| 马关县| 龙门县| 桂林市| 和平区| 长乐市| 建瓯市| 郯城县| 普安县|