我想徽章添加到我的活动的按钮之一。现在我要做的XML。 用徽章的按钮,应该是这样的:
我已经做了泡,用里面的文字 RelativeLayout的
:
< RelativeLayout的机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< ImageView的机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:adjustViewBounds =真
机器人:SRC =@可绘制/徽章
机器人:layout_centerInParent =真/>
< TextView的Android的:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSTYLE =黑体
机器人:文本=2
机器人:layout_centerInParent =真/>
< / RelativeLayout的>
但我不能找到一种方法,将它放在这里,使它在纵向和横向与同一个XML工作。
在Buttoms在活动
是这样的:
<按钮机器人:ID =@ + ID / new_releases_button
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@可绘制/ ic_button_selector
机器人:文本=@字符串/ new_releases_title
机器人:文字颜色=#FFFFFF
机器人:TEXTSIZE =20SP
机器人:重力=center_vertical
机器人:以下属性来=12dp
机器人:layout_marginTop =15dp
机器人:layout_below =@ ID / coming_soon_button
机器人:的onClick =newReleaseClick
机器人:layout_centerHorizontal =真/>
<按钮机器人:ID =@ + ID / top_sellers_button
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@可绘制/ ic_button_selector
机器人:文本=@字符串/ top_sellers_title
机器人:文字颜色=#FFFFFF
机器人:TEXTSIZE =20SP
机器人:重力=center_vertical
机器人:以下属性来=12dp
机器人:layout_marginTop =15dp
机器人:layout_below =@ ID / new_releases_button
机器人:的onClick =topSellersClick
机器人:layout_centerHorizontal =真/>
和这里有两个资源:
我应该怎么做的XML?
编辑: 最好的方法,到目前为止,但它仍然无法正常工作:
< XML版本=1.0编码=UTF-8&GT?;
<的FrameLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<按钮机器人:ID =@ + ID / discounts_button
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@可绘制/ ic_button_selector
机器人:文本=@字符串/ discounts_title
机器人:文字颜色=#FFFFFF
机器人:TEXTSIZE =20SP
机器人:的onClick =discountsClick
机器人:layout_marginTop =40dp
机器人:layout_marginLeft =20dp/>
< RelativeLayout的机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =顶|留下>
< ImageView的机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:adjustViewBounds =真
机器人:SRC =@可绘制/徽章
机器人:layout_centerInParent =真/>
< TextView的Android的:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:TEXTSTYLE =黑体
机器人:文本=20
机器人:layout_centerInParent =真/>
< / RelativeLayout的>
< /的FrameLayout>
解决方案
使用的FrameLayout
(而不是RelativeLayout的)一个,并把按钮和图像进去。
位置的图像(cirle带号)和按钮
安卓layout_gravity =顶|左
机器人:layout_marginTop =XDP
机器人:layout_marginLeft =XDP
要你的喜好。
I am trying to add a badge to one of my Activity's button. Right now I am trying to do the xml. The Button with the badge, should look like this:
I have already done the bubble and the text inside using a RelativeLayout
:
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/badge"
android:layout_centerInParent="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="2"
android:layout_centerInParent="true" />
</RelativeLayout>
But I can't find a way to place it there and making it work on portrait and landscape with the same xml.
The Buttoms in the Activity
are like this:
<Button android:id="@+id/new_releases_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_button_selector"
android:text="@string/new_releases_title"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:layout_marginTop="15dp"
android:layout_below="@id/coming_soon_button"
android:onClick="newReleaseClick"
android:layout_centerHorizontal="true" />
<Button android:id="@+id/top_sellers_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_button_selector"
android:text="@string/top_sellers_title"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:gravity="center_vertical"
android:paddingLeft="12dp"
android:layout_marginTop="15dp"
android:layout_below="@id/new_releases_button"
android:onClick="topSellersClick"
android:layout_centerHorizontal="true" />
and here are the two resources:
How should I do the xml?
EDIT: Best approach so far, but it still doesn't work:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/discounts_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_button_selector"
android:text="@string/discounts_title"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:onClick="discountsClick"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"/>
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/badge"
android:layout_centerInParent="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="20"
android:layout_centerInParent="true" />
</RelativeLayout>
</FrameLayout>
解决方案
Use a FrameLayout
(instead of RelativeLayout) and put button and image into it.
Position the image (cirle with number) and button via
android:layout_gravity="top|left"
android:layout_marginTop="Xdp"
android:layout_marginLeft="Xdp"
to your likes.
上一篇:Android电子市场 - 时间两次更新之间等待两次、电子市场、时间、Android
下一篇:问题使用这些工具在Android SDK / Android的可执行推出的Android AVM / SDK GUI。 Ubuntu的10.04,i686的可执行、工具、问题、Android