Android 表徵圖右上方添加數字提醒

來源:互聯網
上載者:User

標籤:android   style   class   blog   c   code   

方法一:使用開源項目ViewBadger,github上的地址:https://github.com/jgilfelt/android-viewbadger效果:
[java] view plaincopy
  1. <TextView  
  2.        android:id="@+id/tv1"  
  3.        android:layout_width="wrap_content"  
  4.        android:layout_height="wrap_content"  
  5.        android:padding="15dp"  
  6.        android:text="文本1" />  
[java] view plaincopy
  1. <span style="font-family: Arial, Helvetica, sans-serif;"></span>  
[java] view plaincopy
  1. tv = (TextView) findViewById(R.id.tv1);  
  2. BadgeView badgeView = new BadgeView(MainActivity.this, tv);  //執行個體化BadgeView  
  3.          badgeView.setText("12");  
  4. //       badgeView.setTextSize(8.5f);  //設定文字的大小  
  5.          badgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);//設定在右上方  
  6.          badgeView.setTextColor(Color.DKGRAY);  //字型的設定顏色  
  7.          badgeView.show(); //顯示  

[java] view plaincopy
  1.   
這樣就實現了上面的效果,注意引用開源項目ViewBadger時,要和建立的工程檔案在同一個檔案夾內,否則會出錯的 方法二:用架構架構布局FrameLayout效果:布局如下:這樣就可以了 [java] view plaincopy
  1. <FrameLayout  
  2.         android:id="@+id/frameLayout1"  
  3.         android:layout_width="wrap_content"  
  4.         android:layout_height="wrap_content" >  
  5.   
  6.         <TextView  
  7.             android:id="@+id/textView1"  
  8.             android:layout_width="wrap_content"  
  9.             android:layout_height="wrap_content"  
  10.             android:padding="10dp"  
  11.             android:text="文本2" />  
  12.   
  13.         <TextView  
  14.             android:layout_width="wrap_content"  
  15.             android:layout_height="wrap_content"  
  16.             android:layout_gravity="top|right"  
  17.             android:background="#FF0000"  
  18.             android:text="23"  
  19.             android:textColor="@android:color/white" />  
  20.   
  21.         </FrameLayout>  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.