2013-03-14 68 views
0

我需要實現這個mockap enter image description here什麼是畫的最好方式「的新項目計數」

它是灰色的標誌沒有問題。它是TextView和TableLayout中的PNG文件。

但是,我不知道,如何把小綠色的圓圈放在一個角落。這個圈子的意思是「有新消息,需要注意什麼」。它可以或不可以。它可以包含不同的數字。

我的想法 - 用圓圈繪製MyView(我也在PNG中)和數字。但是,我如何計算「父母」角落的座標?

你會怎麼做?

回答

1

您可以使用RelativeLayout將新物品計數器放在灰色圖標的角落上方。例如,以下xml是佈局中的單個單元格:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <ImageView 
     android:id="@+id/gray_icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:background="@drawable/some_gray_icon" /> 
    <TextView 
     android:id="@+id/new_items_counter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@id/gray_icon" 
     android:layout_alignTop="@id/gray_icon" 
     android:background="@drawable/green_circle_icon" 
     android:text="2" 
     android:textColor="@android:color/white" 
     android:textSize="16sp" /> 
</RelativeLayout> 

如果要將計數器向上或向右移動,請使用具有負值的邊距。

android:layout_marginTop="-5dp" 
android:layout_marginRight="-5dp" 

使用這種方法,您必須更新計數器值和代碼的可見性。

+0

Perfecto!謝謝! – 2013-03-14 08:42:58

1

您可以使用ViewBadger庫,允許您使用幾行代碼執行此類操作。

相關問題