Mark Worsnop
Mark Worsnop

Reputation: 4467

Android Java how to make single bar graphic

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?

Upvotes: 0

Views: 636

Answers (2)

Kevin Coppock
Kevin Coppock

Reputation: 134714

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.

Upvotes: 3

justinl
justinl

Reputation: 10548

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

Upvotes: 0

Related Questions