Android 帶角標的ImageView(微博,QQ訊息提示),androidimageview

來源:互聯網
上載者:User

Android 帶角標的ImageView(微博,QQ訊息提示),androidimageview

角標繪製過程:用畫筆量出一個字元的寬度作為角標背景的半徑(R),然後判斷傳入字串的總長度
如果只有一位字元:那麼就以 R 為半徑,畫一個圓,然後在圓中寫上數字
如果有兩位以上的字元,就不能單純用一個圓了,用畫筆測量字串的完整長度( len ),然後在右上方畫一個圓,在這個圓的圓心左邊 len 長度的位置 作為圓心再畫一個圓,最後以這個兩個圓的上下頂點(一共四個)構成一個矩形,進行填充

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

效果如下:

整合方法

在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();            }        });    }
0
0
    查看評論

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.