带有两个图像和文本的 Android 按钮

标签 android xml button

我正在尝试构建 Android 应用程序,需要构建一个包含两个图像和一些文本的按钮。

这是示例图片:

enter image description here

我如何在 android 中构建此按钮?任何帮助将不胜感激。

最佳答案

这里有一些代码可以帮助您入门。让我们从背景开始。如果该背景未提供给您而您必须自己创建,请创建一个 custom_button_bg.xml 文件并添加到您的可绘制文件夹中。

custom_button_bg.xml 注意:我只是为你做了基本的形状。根据需要调整阴影和角半径

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:endColor="@color/teal"
        android:startColor="@color/teal"/>
    <corners android:radius="4dp"/>
    <stroke
        android:width="1dp"
        android:color="@color/shadow"/>
</shape>

现在只需创建您的布局,如下所示。只需替换 src 和标签即可。

<RelativeLayout
    android:layout_width="160dp"
    android:layout_height="80dp"
    android:gravity="center_vertical"
    android:background="@drawable/custom_rounded_white_button">

    <ImageView
        android:id="@+id/iv_video_cam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/video_cam"/>

    <TextView
        android:id="@+id/tv_desc"
        android:layout_toRightOf="@+id/iv_video_cam"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="See a Medical \nDoctor Now"/>

    <ImageView
        android:layout_toRightOf="@+id/tv_desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow"/>

</RelativeLayout>

干杯!

关于带有两个图像和文本的 Android 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41046716/

相关文章:

javascript - 单击按钮时隐藏/显示隐藏的 div

java - 在 Activity 之间传递 'data source'

c++ - 使用 wcstod 转换零值

java - ClassCastException VectorDrawable 无法转换为 Animatable

android - Outlined MaterialButton 不显示任何边框

android - 如何在 AsyncTask 运行时禁用 Button? (安卓)

android - 如何更改 ListView 中的文本颜色

android - 设备在 DDMS 中不断消失

android - ViewGroup 中的 View 越多是否意味着性能越差?

java - Jaxb 结合 xml