6

私は次のレイアウトを持っています...

<?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"
              android:background="@drawable/bg_generic_portrait">
  <ListView android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/issue_list_item_background_normal"
            android:listSelector="@drawable/issue_background_selector"
            android:divider="@drawable/separator"
    >
  </ListView>
  <ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:id="@+id/preloader"
    style="@android:style/Widget.ProgressBar.Large"/>

  <TextView android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#FF0000"/>
</LinearLayout>

そしてそれはこのように見えます...http://i.stack.imgur.com/Ra5c6.png

プリローダーも垂直方向の中央に配置したいのですが、何が問題になっていますか?

4

5 に答える 5

12

どういうわけか、layout_gravityはうまく機能しません。次のように、progress_barをlinear_layoutにネストし、そのレイアウトの重力を中央に設定する必要があります。

<LinearLayout android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:gravity="center">
<ProgressBar
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/preloader"
          style="@android:style/Widget.ProgressBar.Large"/>
</LinearLayout>

リストを変更したり何かを追加したりすると面白いことが起こる可能性があるため、重力を最上部の線形レイアウトに設定することはお勧めしません。

于 2012-06-06T18:33:20.160 に答える
1

あなたがやろうとしていることにいくつかの問題があるようです。レイアウトのプログレスバーの上にあるListViewは、その内容に応じて高さを変えることができます。そのため、線形レイアウトを使用してプログレスバーが画面の中央に留まるようにすることはできません。

バックグラウンドでリストにデータをロードしている間、進行状況ダイアログを表示するProgressDialog クラスを 確認することをお勧めします。

または、RelativeLayoutをトップレベルのレイアウトとして使用してProgressBarとListViewをオーバーラップさandroid:layout_centerInParent="true"せ、ProgressBarの属性を指定することもできます。

于 2012-06-06T18:41:51.113 に答える
1

これは、を使用しているため、を使用し、次のように属性 センターをLinearLayout使用することをお勧めします。RelativeLayoutlayout_centerVertical

<ProgressBar
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_centerVertical="true"
    android:id="@+id/preloader"
    style="@android:style/Widget.ProgressBar.Large"/>
于 2012-06-06T18:16:35.243 に答える
0

Listviewどのくらいのスペースを取っているのかわかりませんが、アイテムが必要な場所を実際に定義したい場合は、<RelativeLayout>代わりにを使用することをお勧めします。<LinearLayout>x

于 2012-06-06T18:16:55.090 に答える
0

android:gravity="center"親のLinearLayoutで設定します。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:gravity="center"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
于 2012-06-06T18:18:33.507 に答える