简体   繁体   English

带颜色的 Android TextView 背景图像

[英]Android TextView Background Image With Color

I have a simple table layout, in the one of the row, I have time for sun rise in a text view and I am trying to have sun with purple colour for the row as background.我有一个简单的表格布局,在其中一行中,我有时间在文本视图中看到太阳升起,并且我正在尝试将该行的紫色太阳作为背景。 How can I achieve this?我怎样才能做到这一点? I tried creating an image 1000px x 500px with sun and purple background, However, it does not look good on different screen sizes.我尝试创建一个带有太阳和紫色背景的 1000 像素 x 500 像素的图像,但是,它在不同的屏幕尺寸上看起来不太好。 What is the solution for this?解决这个问题的方法是什么?

Here is an image of what I am trying to achieve这是我想要实现的目标的图像

I have a simple table layout, in the one of the row, I have time for sun rise in a text view and I am trying to have sun with purple colour for the row as background.我有一个简单的表格布局,在其中一行中,我有时间在文本视图中看到太阳升起,并且我正在尝试将该行的紫色太阳作为背景。 How can I achieve this?我怎样才能做到这一点?

Save your image in drawable folder , and in your TextView add this line :将您的图像保存在 drawable 文件夹中,并在您的 TextView 中添加以下行:

android:background = "@drawable/your_imagename_from_drawable_folder"

I tried creating an image 1000px x 500px with sun and purple background, However, it does not look good on different screen sizes.我尝试创建一个带有太阳和紫色背景的 1000 像素 x 500 像素的图像,但是,它在不同的屏幕尺寸上看起来不太好。 What is the solution for this?解决这个问题的方法是什么?

( This is not accurate answer but it will help you ) this online tool will help you creating images , http://labs.rampinteractive.co.uk/android_dp_px_calculator/ for this , first you have to find your emulator_dp and screen size and you can find it from emulator details section and after it you can create some good images for different screen_sizes than your previous attempts . (这不是准确的答案,但它会帮助你)这个在线工具将帮助你创建图像, http://labs.rampinteractive.co.uk/android_dp_px_calculator/为此,首先你必须找到你的 emulator_dp 和屏幕尺寸,然后你可以从模拟器详细信息部分找到它,之后您可以为与之前尝试不同的 screen_sizes 创建一些好的图像。

Did you try with setImageDrawable method ?您是否尝试过使用setImageDrawable方法?

Save your image in drawable folder eg: holder.row.setImageDrawable(getResources().getDrawable(R.drawable.yourImage));将您的图像保存在可绘制文件夹中,例如: holder.row.setImageDrawable(getResources().getDrawable(R.drawable.yourImage));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM