在按键设置文本与按钮底色和文字背景不同 [英] Set Text on Button with button backround and text background differently

查看:332
本文介绍了在按键设置文本与按钮底色和文字背景不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示在GridView中的图像与在底部写有文字。所以我把一个按钮,并设置在该背景上设置壁纸。这给拥有超过我可以做任何工作文本的图像。

I want to Display image in gridview with a text written on it at bottom. So I took a button and set background on that and set wallpaper on that. This gives a image with a text over which I may make any work.

在code我用的是

Button
        android:id="@+id/img"
        android:layout_gravity="center"
        android:gravity="bottom|center"
        android:layout_width="100dp"
        android:paddingBottom="4dp"
        android:textSize="13dp"
        android:layout_height="100dp">
    </Button>

Button imageView = (Button) rowView.findViewById(R.id.img);
        imageView.setText(web[position]);

        imageView.setBackgroundResource(imageId[position]);

和我得到的结果作为第一个形象,但这里的问题是,它是很难读一些图片文字

And I get the result as the first Image but the problem here is It is tough to read the text on some images

我希望文字有自己的后台写在第二图像写入。所以,我必须做什么来实现这一结果。您的建议对我来说是宝贵的。于是好心建议,先谢谢了。

I want the text to be written with its own background as written on second image. So what must I do to achieve this result. Your suggestions are valuable for me. So kindly suggest, Thanks in Advance

推荐答案

试试这个办法,希望这将帮助你解决你的问题。

Try this way,hope this will help you to solve your problem.

colors.xml

<resources>
    <color name="transparent_background">#CC4d4d4d</color>
</resources>

grid_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <FrameLayout
        android:layout_width="100dp"
        android:layout_height="wrap_content">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_launcher"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:gravity="center"
            android:padding="7dp"
            android:background="@color/transparent_background"
            android:text="Games"/>

    </FrameLayout>
</LinearLayout>

这篇关于在按键设置文本与按钮底色和文字背景不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆