android氣泡消息提醒布局


  無論是anroid還是ios,氣泡消息提醒再正常不過了。然而要定義一個氣泡消息提醒確要費一番周折。下面記錄下氣泡提醒布局。

  定義氣泡背景shape_unread_message_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android= "http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:useLevel= "false" >

    <solid android:color= "#FF0000" />

</shape>

  定義氣泡布局,關鍵點是android:layout_gravity="top|right"

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/img_cells"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:src="@mipmap/ic_launcher" />
                <TextView
                    android:id="@+id/tab_unread_message"
                    android:layout_width="14dp"
                    android:layout_height="14dp"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="14dp"
                    android:background="@drawable/shape_unread_message_bg"
                    android:gravity="center"
                    android:textColor="@android:color/white"
                    android:textSize="8sp"
                    android:layout_gravity="top|right"
                    android:visibility="gone"
                    />
            </FrameLayout>

  此處需要注意的是,如果數字過大。出現"..."時無法居中,其實這是英文"..."導致的問題,換成"···"即可。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM