2

DrawerLayout 内に ViewStub があり、ユーザーのニーズに応じてこのスタブを動的に拡張および削除する予定です。

ドロワーは、以下を含む RelativeLayout で構成されます。 1. TextView 2. 上記の ViewStub 3. ListView

ViewStub を拡張しても、結果のビューは ListView を置き換えません。代わりに、ユーザーが見えないように、ListView の下で膨らませます。スタブが膨張したときにリストを押し下げたいと思います。

どうすればこれを解決できますか?

XML コードは次のとおりです。

<RelativeLayout

        android:id="@+id/drawer"
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#dedede"
        android:fitsSystemWindows="true"
        android:orientation="vertical"
        >

        <TextView
            android:id="@+id/drawer_text"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="@android:color/holo_red_light"/>

        <ViewStub
            android:id="@+id/info_stub"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout="@layout/info_entry_stub"
            android:layout_below="@+id/drawer_text"/>

        <ListView
            android:id="@+id/drawernavlist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/holo_orange_dark"
            android:layout_below="@+id/info_stub"
            android:layout_gravity="start">
        </ListView>

    </RelativeLayout>

スタブが指すレイアウト:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/info_entry_stub">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/darker_gray"
        android:text="HELLO"/>


</RelativeLayout>

解決策が見つかりました: ViewStub内に属性を追加して解決しました:

android:inflatedId="@id/info_stub"
4

1 に答える 1