Вопрос

I have been trying to place a View (a ProgressBar to be exact) at specific position on my activity for the past hour, to no avail. My activity has a background image, and I need to align the progress bar with it. Here's a rough estimate of what I need:

*-----------------------*
|                       |
|       15% vertical    |
|                       |
|         XXXXX         |
|         XXXXX         |
|         XXXXX         |
|                       |
|                       |
|                       |
|                       |
|                       |
|                       |
|                       |
|                       |
|                       |
|                       |
*-----------------------*

I have tried solutions in these questions (1, 2, 3), but I'm missing something. Here's the latest manifest I have come up with so far:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="@dimen/activity_horizontal_margin"
        android:orientation="vertical" >

        <View
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="15" />

        <ProgressBar
            android:id="@+id/pbProgress"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminate="true" />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

But my activity looks like this:

*-----------------------*
|                       |
|    20~25% vertical    |
|                       |
|                       |
|                       |
|                       |
|XXXXX                  |
|XXXXX                  |
|XXXXX                  |
|                       |
|                       |
|                       |
|                       |
|                       |
|                       |
|                       |
*-----------------------*

Can someone please help me align this progress bar?

Thanks in advance

Это было полезно?

Решение

Try to add you ProgressBar to layout with weight.

Instead of

<ProgressBar
            android:id="@+id/pbProgress"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminate="true" />

write something like this:

<LinearLayout
  android:gravity="center_horizontal"
  android:layout_weight="85"
  android:layout_width="match_parent"
  android:layout_height="0dp">
   <ProgressBar
            android:id="@+id/pbProgress"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminate="true" />
</LinearLayout>

update: btw, instead of fill_parent better use match_parent

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top