android - 在 Android 中可绘制的按钮内添加文本

标签 android xml xamarin

我在 Xamarin 中有 Android 项目。我需要做的是在放置在 Button 中的图像(绿点)内添加文本。

如您所见,我将绿点添加为可绘制对象。所以也许我应该制作自定义可绘制对象,它将组合 TextView 和图像?

这就是它现在的样子/我正在努力实现的目标:

enter image description here

按钮 XML

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/button_synchronize"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/button_action"
        android:minHeight="60dp"
        android:maxHeight="60dp"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:paddingLeft="20dp"
        android:paddingRight="60dp"
        android:layout_alignParentBottom="true"
        android:text="Synkronisering"
        android:drawableRight="@drawable/ic_green_dot"
        android:drawablePadding="3dp"
        android:gravity="center" />
</RelativeLayout>

选择器 XML

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<solid android:color="@color/main_orange_color" />
<stroke android:width="1dp" android:color="@color/main_grey_color" />
<corners android:radius="4dp" />
<padding android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="3dp" />
</shape>
</item>
</layer-list>
</item>
</selector>

最佳答案

您可以从宽度和高度都设置为 wrap_contentFrameLayout 开始。然后,添加 Button 作为底部的 View 。添加应用了适当样式的 TextView。适本地改变它的 layout_gravity

更多请看:http://blog.neteril.org/blog/2013/10/10/framelayout-your-best-ui-friend/

The secret of FrameLayout is how it layouts its children. Although normally designed to contain one item, it will happily stack up other element on top of each other. Thus FrameLayout is essentially a way to manipulate the Z-order of views on the screen.

关于android - 在 Android 中可绘制的按钮内添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26759979/

相关文章:

java - Android 中的 Asynctask 多个连续 URL 请求

java - 如何在自定义 ListView ArrayList 中进行排序以及如何使其在 Spinner 中工作?

android - 如何在项目点击 Activity 中调用两个 fragment

xml - 使用Groovy附加到xml文件的属性值

android - android 应用程序和云存储(文件、数据库)之间的一种数据存储方式

xml - 用于 Web 服务的 SOAP 还是 REST?

android - 什么是 fragment_main.xml?

Xamarin iOS : Why required to call StartAccessingSecurityScopedResource and release it in the DocPicker Sample

visual-studio - iPhone 模拟器在 Visual Studio for Mac 中的 Debug模式下不显示。 Xamarin.IOS

c# - 在设备上存储密码