4

Android 1.5 の RelativeLayout でビューがオーバーラップするという問題が発生しています... Android 1.6 以降ではすべて正常に動作しています。

Android 1.5 には RelativeLayout に関するいくつかの問題があることは理解していますが、StackOverflow または Android 初心者グループで特定の問題を見つけることができませんでした。

私のレイアウトは 4 つのセクションで構成され、それぞれが TextView、Gallery、および垂直方向に配置された別の TextView で構成されています。

実行中のアプリ
最近のアプリ
サービス
プロセス

これらのアイテムの 4 つのセットがすべて表示されると、すべて正常に動作します。ただし、私のアプリでは、ユーザーがこれらの一部を表示しないように指定できます。ユーザーが実行中のアプリ、最近のアプリ、またはサービスをオフにすると、残りのセクションがすべて突然重複します。

これが私のレイアウト用のコードです。何が間違っているのかわかりません。ユーザーがセクションの表示をオフにすると、View.GONE 可視性設定を使用します。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_vertical"
    android:layout_gravity="center_vertical"
    android:background="@null"
>
<!-- Running Gallery View Items -->
<TextView 
    style="@style/TitleText"
    android:id="@+id/running_gallery_title_text_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:paddingLeft="1sp"
    android:paddingRight="10sp"
    android:text="@string/running_title"
/>

<Gallery
    android:id="@+id/running_gallery_id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/running_gallery_title_text_id"
    android:spacing="5sp"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:unselectedAlpha=".5"
/>

<TextView 
    style="@style/SubTitleText"
    android:id="@+id/running_gallery_current_text_id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/running_gallery_id"
    android:gravity="center_horizontal"
/>

<!-- Recent Gallery View Items -->
<TextView 
    style="@style/TitleText"
    android:id="@+id/recent_gallery_title_text_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/running_gallery_current_text_id"
    android:gravity="left"
    android:paddingLeft="1sp"
    android:paddingRight="10sp"
    android:text="@string/recent_title"
/>

<Gallery
    android:id="@+id/recent_gallery_id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/recent_gallery_title_text_id"
    android:spacing="5sp"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:unselectedAlpha=".5"
/>

<TextView 
    style="@style/SubTitleText"
    android:id="@+id/recent_gallery_current_text_id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/recent_gallery_id"
    android:gravity="center_horizontal"
/>

<!-- Service Gallery View Items -->
<TextView 
    style="@style/TitleText"
    android:id="@+id/service_gallery_title_text_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/recent_gallery_current_text_id"
    android:gravity="left"
    android:paddingLeft="1sp"
    android:paddingRight="10sp"
    android:text="@string/service_title"
/>

<Gallery
    android:id="@+id/service_gallery_id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/service_gallery_title_text_id"
    android:spacing="5sp"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:unselectedAlpha=".5"
/>

<TextView 
    style="@style/SubTitleText"
    android:id="@+id/service_gallery_current_text_id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/service_gallery_id"
    android:gravity="center_horizontal"
/>
</RelativeLayout>

これを短く保つために(やや無駄な)試みで、プロセスセクションのxmlを省略しました...

Android 1.5 でこれを機能させるにはどうすればよいですか? すべてが表示されているときに正常に動作するため、xml 内のビューを並べ替えるだけの問題ではないと思います。

4

1 に答える 1

4

考えられる解決策は次の 2 つです。

  • 要素の高さを 0 または 1 px に設定し、可視性を GONE ではなく INVISIBLE に設定してみてください。
  • 各 Gallery/TextView を wrap_height に設定された LinearLayout でラップし、サブビューの代わりにレイアウトに上/下を設定します。次に、サブ要素を View.GONE に設定し、相対配置に使用される線形レイアウトを表示したままにしますが、ラップされた高さは 0 にします。

どちらのソリューションのアイデアも、View.GONE のビューに対して相対的に何かを配置しないようにすることです。それがあなたが遭遇しているバグの原因だと思います。

私が尋ねるかもしれませんが、なぜここで RelativeLayout を使用する必要があるのでしょうか? 一目でわかるように、ここにあるものはすべて垂直方向の LinearLayout にうまく適合し、実際、この配置では概念的に単純に見えます。

于 2010-04-04T18:18:14.193 に答える