質問

私は、ヘッダー、ボディ(リスト)、フッターを使用して、lerativeLayoutを作成しようとしています。ヘッダーは、すべての上(上部に整列)、ボディ(リスト)がヘッダー(スクロールするとき)の下にあり、フッター(下に位置付けられている)を体の上に(リスト)にすることを望みます(リスト)。

物事がどのように見えるかに関しては、私はなんとかそうすることができましたが、どうやらXMLレイアウトは、リスト項目をクリックしたときに抱えてきた問題の原因です(こちらをご覧ください, そしてここ).

問題を解決するために、LinearLayoutでListViewをラップし、ヘッダーとフッター(XML)の間に置く必要がありました。これにより、[問題]をクリックするリスト項目が解決しますが、新しい問題は作成されます。フッターは、スクロールするときにヘッダーの下にある場合でも、最後のListViewアイテムを隠します。

私はここでかなり必死です:

これは、完璧なレイアウトを作成しますが、リスト項目をクリックする問題を引き起こすXMLです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#ffffff"
    >
    <RelativeLayout
        android:background="@drawable/top_background"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:id="@+id/top_control_bar"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="Droidmarks"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/add_bookmark"
            android:textSize="20dip"
            android:textColor="#a0cb26"
            android:shadowColor="#7a9b1b"
            android:shadowRadius="5"
            android:layout_marginLeft="5dip"
            android:gravity="left|center" />
        <Button
            android:id="@+id/add_bookmark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center"
            android:layout_alignParentRight="true"
            android:text="Add"
        />
    </RelativeLayout>
    <LinearLayout
        android:id="@+id/bottom_control_bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/top_background"
        android:visibility="invisible"
        >
        <Button
            android:id="@+id/test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center"
            android:layout_alignParentRight="true"
            android:text="Add"
        />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/top_control_bar"
        android:layout_above="@id/bottom_control_bar"
        android:drawSelectorOnTop="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:cacheColorHint="#ffffff"
        android:listSelector="@drawable/selected_item"
        />
    <TextView android:id="@android:id/empty" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="No Bookmarks found. You can add one by clicking the star."
        android:layout_below="@id/top_control_bar" android:layout_above="@id/bottom_control_bar" />
</RelativeLayout>

これは、最後のリスト項目を非表示にしますが、クリックの問題を解決するXMLです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#ffffff"
    >
    <RelativeLayout
        android:background="@drawable/top_background"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:id="@+id/top_control_bar"
        android:layout_alignParentTop="true"
        >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="Droidmarks"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/add_bookmark"
            android:textSize="20dip"
            android:textColor="#a0cb26"
            android:shadowColor="#7a9b1b"
            android:shadowRadius="5"
            android:layout_marginLeft="5dip"
            android:gravity="left|center" />
        <Button
            android:id="@+id/add_bookmark"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center"
            android:layout_alignParentRight="true"
            android:text="Add"
        />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/listArea"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@id/top_control_bar"
        >
        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="false"
            android:cacheColorHint="#ffffff" />
        <TextView android:id="@android:id/empty" android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No Bookmarks found. You can add one by clicking the star." />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_control_bar"
        android:layout_above="@id/listArea"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@drawable/top_background"
        android:orientation="horizontal"
        android:visibility="visible"
        >
        <Button
        android:id="@+id/test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center"
        android:layout_alignParentRight="true"
        android:text="Add"
    />
    </LinearLayout>
</RelativeLayout>

両方の問題の解決策を何らかの形で見つけるための助けに感謝します!

ありがとうございました!

役に立ちましたか?

解決

コンテナにRelativeLayoutを使用している理由を聞いてもいいですか? wheight_height-setヘッダーとフッターの後に残りのすべての領域を取得するために設定された、重みのあるセンターエリア(listView)を備えたLinearLayoutを使用するのに最適な場所のようです。 RelativeLayoutsは、水平要素と垂直要素の両方を含む深くネストされたレイアウトを簡素化するのに最適ですが、ここの外層にはとにかく3つの垂直要素のみが含まれているため、LinearLayoutを使用して orientation:vertical ここで何かが足りないのでなければ。

編集:要するに、これを試してください。これにより、固定された高さヘッダー、ラッピングハイイトフッター、センターエリアが残りのすべてのスペースを占める必要があります。外側のレイアウトが設定されていることを確認してください fill_parent 高さと中央の領域は固定された高さに設定されていますが、 layout_weight="1". 。レイアウト_Weightを使用しているときにベースlayout_heightに「0px」を使用するのが好きです。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#ffffff"
    >
    <RelativeLayout
        android:background="@drawable/top_background"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:id="@+id/top_control_bar"
        > <!-- snip - inner contents unchanged -->
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/listArea"
        android:layout_width="fill_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:orientation="horizontal"
        ><!-- snip - inner contents unchanged -->
    </LinearLayout>

    <LinearLayout
        android:id="@+id/bottom_control_bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/top_background"
        android:orientation="horizontal"
        android:visibility="visible"
        ><!-- snip - inner contents unchanged -->
    </LinearLayout>
</LinearLayout>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top