2011-12-07 29 views
0

ヘッダーとフッターを含むレイアウトを取得するには、次の設定が必要です。アクティビティはダイアログに表示されるので、先頭の要素の高さを "wrap_content"に設定します。アンドロイドのドキュメントに関して、alignParentBottm = "true"を子要素に設定している限り、これは不可能です。alignParentBottom = "true"のないRelativeLayoutのヘッダー、コンテンツ、フッター

誰かがLinearLayoutを使用するように提案し、プログラムによってmaxHeightを設定しました。 alignParentBottom = "true"を避ける他の方法はありますか?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:id="@+id/LNL_TOP" 
     android:layout_width="match_parent" 
     android:layout_height="60dip" 
    android:layout_alignParentTop="true"> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/LNL_BOTTOM" 
     android:layout_width="match_parent" 
     android:layout_height="60dip" 
     android:layout_alignParentBottom="true"> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/LNL_CONTENT" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/LNL_TOP" 
    android:layout_above="@+id/LNL_BOTTOM"> 

     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 

    </LinearLayout> 
</RelativeLayout> 

ここでは、現在の外観をイメージしています。レイアウトでコンテンツを囲み、リストの下の空きスペースを避けてください。

enter image description here

+0

画像を投稿することはできますか? –

+0

私の質問に画像を追加 – timoschloesser

+0

シンプルなLinearLayoutを使用すると何が問題になりますか? <のLinearLayout layout_height = "wrap_content"> Jave

答えて

4

ではなく、垂直のLinearLayoutを使用します。これ以上のスペースがなくなるまでこれにより

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="HEAD"/> 
    <!--LinearLayout containing the list here, to go with your posted code, 
it would also work to just have the list outside the layout.--> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_weight="1"> 
     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"/> 
    </LinearLayout> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="FOOT"/> 
</LinearLayout> 

を、体がそのコンテンツと一緒に成長します。それから、フッタの後ろに下がり始めます(コンテンツにListViewを使用すると問題はありませんので、ビューは最大サイズに拡大して停止し、スクロールが機能します)。

+0

私はその理由を完全に理解していませんが、それは絶対にうまくいきます。ありがとう! – timoschloesser

+0

ようこそ。 – Jave

0

あなたは、これはダイアログウィンドウであることを特徴とするので、あなたは、ある意味で、あなたが望んでいた場合は無期限ダイアログの高さを拡張することができます。ビューの一番下に合わせるのではなく、一番下の要素のlayout_marginTopを使用して、望みどおりに低くしてください。 LNL_CONTENTの高さをmatch_parentに設定した場合は、その間のスペースを埋めるでしょう。

関連する問題