ALL,
我到处都能看到有关如何使其适用于应用程序图标的回复。我的情况有点不同。
在我的程序中,我有一个显示图像的 ListView。每个图像都与下面的对象相关联。
我想做的是创建一个类似于 iPhone 徽章通知的设计,但适用于视图中的所有图像。
试图询问谷歌,我发现this http://tech.chitgoks.com/2012/07/06/how-to-add-a-notification-alert-badge-in-an-android-imageview/关联。问题是 - 它不起作用。我正在使用 2.2 内核的 LG Android 手机上进行测试,我看到的只是一个小红点,它甚至不位于图像本身左侧高几个像素的位置。
这是我的代码:
<?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/user_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/user_image_description"
android:src="@drawable/placeholder"
/>
<TextView
android:id="@+id/user_messages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/icon"
android:layout_alignBottom="@id/icon"
android:background="@color/red"
android:textColor="@color/silver"
android:layout_marginLeft="-4dp"
android:layout_marginBottom="-4dp"
android:textSize="12sp"
android:textStyle="bold"
android:gravity="center"
/>
</RelativeLayout>
有人可以看一下吗?
我尝试更改边距和文本大小,但没有改变任何内容。
谢谢。
试试这个方法
<?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"
android:visibility="visible" />
</RelativeLayout>
Create drawable/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>
Output:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)