Android: Can a static horizontal progress bar be e

2019-07-18 12:24发布

问题:

I don't think this is possible, but can a static (determinate) horizontal progress bar be embedded in a Textview?

Update1: I am trying to create a progress bar similar to that of the iPhone, but I also need text above it. Here is a picture: http://i.stack.imgur.com/aDFU9.png

Update2:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<ProgressBar
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:id="@+id/pbar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:max="100"
    android:progress="45"
    android:maxHeight="5sp"
    android:layout_marginRight="5dp" />
</LinearLayout>

Here is the picture: http://i.stack.imgur.com/ypimG.png

Now my goal is to make this look like the previous picture.

回答1:

As TextView can't contain another view (there is no addChild() method) the answer is no.

Update: After looking at the picture, you should use a LinearLayout which contains a TextView and a ProgressBar.



回答2:

You can use

Prog = (ProgressBar) findViewById(R.id.pbar1);
Prog.setProgress((int) rounded);