2011-12-12 68 views
5

我想要设计以下用户界面。任何人都可以给我一个例子或建议一些实施的源代码?通知用户界面帮助图标

Icon I want

+0

你想完成什么?图标,文字,角落中的符号,编号?它背后的代码或图形? – Tobbe

+2

我已经100%自信地回答了这个问题。请稍微搜索一下,答案肯定在SO上。 – 2011-12-12 15:23:41

+0

@Tobbe我只是想要图形我的e-xml – Altaf

回答

9

就显示在不同的项目,但你的应用程序(即TextViewTabHostImageView等)

关于显示的应用程序图标徽章里面徽章Here is Project on Git Hub,这是不可能的,因为这不是Android的方式显示通知。 Android框架支持使用Status bar Notifications

+0

BUTSM短信图标有图标上的通知,如果它不工作的方式如何工作??????????? –

+0

是的,一些三星Android设备在选定的应用程序中显示图标徽章。它可能是供应商特定的。你在谈论什么设备,操作系统和供应商? –

+0

我有三星Galaxy Ace和Android版本是2.3.3。你能告诉我如何做这样的应用程序图标通知?我需要样品,如果你知道在哪里看到。 –

2

可以使用的RelativeLayout有两个孩子,一个是图标,一个用于徽章。 该图标需要额外的填充,使徽章稍微偏离它。 徽章的位置与parentTop和parentRight对齐。

6

如果你想建立在左上角的通知图标是为下一段代码一样简单:

Bitmap1必须大于bitmap2做大,你的情况我会把它奉劝是一个具有透明背景的PNG图像,以允许通知气泡在图像的其余部分之外。

 private Bitmap overlay(Bitmap bitmap1, Bitmap bitmap2) { 
      Bitmap bmOverlay = Bitmap.createBitmap(bitmap1.getWidth(), bitmap1.getHeight(), bitmap1.getConfig()); 
      Canvas canvas = new Canvas(bmOverlay); 
      canvas.drawBitmap(bitmap1, new Matrix(), null); 
      canvas.drawBitmap(bitmap2, new Matrix(), null); 
      return bmOverlay; 
     } 

否则,如果你想要它在右上角,你应该尝试任何Canvas.drawBitmap的其他规范。

例如:

canvas.drawBitmap(Bitmap bitmap, float left, float top, Paint paint); 

尝试做喜欢的事:

private Bitmap overlay(Bitmap bitmap1, Bitmap bitmap2) { 
      Bitmap bmOverlay = Bitmap.createBitmap(bitmap1.getWidth(), bitmap1.getHeight(), bitmap1.getConfig()); 
      Canvas canvas = new Canvas(bmOverlay); 
      canvas.drawBitmap(bitmap1, new Matrix(), null); 
      canvas.drawBitmap(bitmap2, bitmap1.getWidth()-bitmap2.getWidth(), 
           0,null); 
      return bmOverlay; 
     } 

如果你想一切都是如何做到这一点的XML,那么你应该创建一个RelativeLayout的,然后在其上添加这两个图像并将通知气泡对齐。这应该可以做到。您仍然必须拥有透明背景的PNG图像。

我希望这足以满足你想要做的事情。

+1

+1来回答如何在XML和实现中进行布局。 –

+0

+1为好的答案,请详细说明在哪里实施它.... – Dhana

2

这是您的应用程序小部件图标徽章计数显示的源代码。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/main_widget" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="center_horizontal" 
android:layout_marginTop="20dip" 
android:focusable="true" > 

<ImageView 
    android:id="@+id/icon" 
    android:layout_width="60dip" 
    android:layout_height="60dip" 
    android:layout_marginTop="8dp" 
    android:background="@drawable/logo" 
    android:contentDescription="image" 
    android:scaleType="center" /> 

<TextView 
    android:id="@+id/title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/icon" 
    android:gravity="center" 
    android:paddingLeft="3dp" 
    android:paddingTop="10dp" 
    android:shadowColor="#000000" 
    android:shadowDx="1" 
    android:shadowDy="1" 
    android:shadowRadius="1.5" 
    android:text="@string/app_name" 
    android:textColor="#FFF" /> 

<TextView 
    android:id="@+id/txt_count" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="-10dip" 
    android:layout_toRightOf="@+id/icon" 
    android:background="@drawable/badge_count2" 
    android:contentDescription="badge" 
    android:gravity="center" 
    android:text="1" 
    android:textColor="@color/White" 
    android:textStyle="bold" /> 

</RelativeLayout> 

并且您还需要此badge_count2.xml可绘制文件。

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 

<solid android:color="@color/red" > 
</solid> 

<stroke 
    android:width="2dp" 
    android:color="#FFFFFF" > 
</stroke> 

<padding 
    android:bottom="2dp" 
    android:left="7dp" 
    android:right="7dp" 
    android:top="3dp" /> 

<corners android:radius="10dp" > 
</corners>