【发布时间】:2013-09-25 16:02:15
【问题描述】:
我想在按钮旁边添加一个小计数器,以显示某些物品的剩余数量,例如,剩余未使用的小费数量。目标布局如下所示:
问题:
我研究了网络,发现有人说要为每个数量使用不同的图片。但是数量可以达到100个怎么解决呢?真的有必要画出来吗?
我正在考虑在RelativeLayout 中将两个按钮粘在一起,这样当用户按下底部按钮时,顶部按钮将向上和向下计数,setText 本身,但是有更好的解决方案或导入吗?
编辑:
感谢 Rupesh 的代码和建议!我已经实现如下。但是您知道如何将红色圆圈文本视图进一步向右移动吗?并且 20 也无法正确显示在红色圆圈中...
代码:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp" >
<Button
android:id="@+id/button_tip"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="5dp"
android:background="@drawable/orange_btn"
android:onClick="button_tip_click"
android:text="Hello" />
<TextView
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_gravity="top|right"
android:background="@drawable/red_circle_btn"
android:gravity="center"
android:text="20"
android:textColor="@color/white"
android:textSize="8sp"
android:textStyle="bold" />
</FrameLayout>
【问题讨论】:
-
查看我的解决方案,使用自定义 Drawable 你可以解决你的两个问题