【问题标题】:How to implement a overlapping TextView in a ImageView, which combinely works as a Button?如何在 ImageView 中实现重叠的 TextView,它可以作为按钮使用?
【发布时间】:2019-01-01 06:37:29
【问题描述】:

我是 Android 开发新手,我需要知道是否可以将 imageView 和 TextView 重叠在一起形成一个按钮。它应该与我共享的图像相似,并且我需要将其框在具有 2 列的 GridLayout 中。如果我对每个 imageView 和 textView 使用 FrameLayout 它变得有点复杂,是否有任何替代方法?

【问题讨论】:

标签: android-studio android-layout button textview imageview


【解决方案1】:

试试这个并运行...如果发生任何错误请告诉我我会帮忙

 <?xml version="1.0" encoding="utf-8"?>
<GridLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <Button
            android:id="@+id/img_category"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/your_image"
            android:scaleType="centerCrop"
            android:textColor="@color/colorBlack"
            android:text="Title"
            android:textSize="25sp"/>

</GridLayout>

【讨论】:

  • 但我需要在 GridLayout 中使用它,它应该是一个按钮!
  • 检查我编辑的答案。您可以根据您的要求自定义它@HarishV
  • 谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多