开发者

How can I make a progress indicator in a listview by coloring the background partly?

For my podcast app I have a listv开发者_运维知识库iew with the downloaded episodes. The user can click on one of the items and it will play. When it's finished it will play the next in the list and so on.

However, I would like to indicate the played portion by coloring the background of the row. I do not want a progress bar widget. So lets say the user has played half of the epsiode, then the left half of the row should have say a green background color.

Unfortunately, I have no ideas how to implement that although it sounds quite simple.

Here is my code so far. playPostion is a number from 0 to 1000 that gives the relative position, so 500 is halfways played etc.

ListAdapter adapter = new SimpleCursorAdapter(this,
        R.layout.player_row_view,
        c,
        new String[] {"title","date","hour"},
        new int[] {R.id.playertitle, R.id.playerdate, R.id.playerhour}) {

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                View row = super.getView(position, convertView, parent);
                int playPosition = c.getInt(c.getColumnIndex("position"));
                // playPosition contains the position
                return row;
        }

};

How can change the background of the current row according to the playPosition?


An idea could be having a FrameLayout, with two layouts on top of each other. You could then use one for background and the other for foreground.

In the background layout you should have two layouts. One with the default color and one with the progress color. When you want to update progress, remove the layouts currently in the background and replace them with two new layouts with layout_weight set according to your progress values e.g. if the progress is 500 you would have each set to layout_weight="0.500f".

I don't think it's the best solution - but if you don't want to use a ProgressBar, this is probably the direction you need to take.


I'd try to wrap your row item into FrameLayout and add a ProgressBar to it, so it would be on background. Then you'd be able to manage that bar setting progress as you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜