Android Java如何制作单条形图

发布于 2024-10-09 03:50:47 字数 212 浏览 0 评论 0原文

我需要显示一个“图形”,其中框的一部分被着色。 在框中它会有文本,但我希望能够在背景上添加颜色以显示数字有多高。看我用excel做的图表。 (我想我不被允许上传图片。所以不知道如何解释这个..
点击此处查看Excel图片

有人知道怎么做吗?

I need to show a "graphic" with part of the box colored in.
In the box it it will have text, but then I want to be able to put a color on the background to show how high the numbers are. see the graphic I made in excel. (I guess I am not allowed to upload a picture. So not sure how to explain this..
Click here to see the excel picture

Anyone know how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫林﹌晚霞¤ 2024-10-16 03:50:47

您可以简单地创建一个 XML Drawable,如下所示(保存在 res/drawable 下):

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    <gradient
        android:angle="0"
        android:type="linear"
        android:startColor="#FF00FF00"
        android:endColor="#FFFFFFFF"
        />
    <stroke
        android:width="1dp"
        android:color="#FF000000"
        />
/>

然后只需使用 TextView,将此 Drawable 设置为您的 android:background 属性。

You can simply make an XML Drawable, something like this (save under res/drawable):

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    <gradient
        android:angle="0"
        android:type="linear"
        android:startColor="#FF00FF00"
        android:endColor="#FFFFFFFF"
        />
    <stroke
        android:width="1dp"
        android:color="#FF000000"
        />
/>

then just use a TextView, with this Drawable set as your android:background attribute.

岁月如刀 2024-10-16 03:50:47

您希望颜色为每个值动态改变颜色吗?或者您是否同意只使用几种颜色“级别”(例如红色、黄色、绿色)。

更简单的方法是只设置一些颜色并在 Photoshop 中创建这些渐变,然后使用背景属性将这些纹理应用到 ImageView 的背面。

以下是有关视图如何工作的一些教程: http://developer.android.com/资源/tutorials/views/index.html

Do you want the colour to dynamically change colour for each value? Or are you okay with just having a few colour "levels" (e.g. red, yellow, green).

The easier route would be to just have a few set colours and create those gradients in photoshop and then apply those textures to the back of an ImageView using the background attribute.

Here are some tutorials on how views work: http://developer.android.com/resources/tutorials/views/index.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文