2011-01-13 18 views
6

レイアウトを作成したいと思います。水平と垂直のLinearLayoutを上と下に、リストビューを中央に塗りつぶします。レイアウトの問題:上部と下部に何かを配置する方法は?

どのようにmain.xmlを定義できますか。

一番上に水平のLinearLayout、一番下にTextView、中間にListViewを入れてレイアウトを作成しようとしました。大丈夫ですか?しかし、下のTextViewをLinearLayoutに変更すると、下のLinearLayoutが消えます。

<?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" 
    > 
    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 
     <TextView 
      android:textSize="12px" 
      android:text="something here" 
      android:layout_width="50px" 
      android:layout_height="wrap_content" 
      /> 
     <TextView 
      android:textSize="12px" 
      android:text="something here" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /> 
    </LinearLayout> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="bottom" 
     > 
     <ListView 
      android:id="@+id/listbody" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      > 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12px" 
       android:text="50%" 
       /> 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12px" 
       android:text="50%" 
       /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

誰でもアドバイスできますか? 助けてください。 RelativeLayoutにセット全体を含む

答えて

11

してみてください。サイズのものを使って編集

<?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" > 

    <LinearLayout 
     android:id="@+id/top_linear_layout_id" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" > 
    </LinearLayout> 

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/bottom_linear_layout_id" 
     android:layout_below="@id/top_linear_layout_id" /> 

    <LinearLayout 
     android:id="@+id/bottom_linear_layout_id" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 
    </LinearLayout> 
</RelativeLayout> 

+0

ここで、LinearLayoutはListViewと重複します。 LinearLayoutを底に定義するのは間違っているはずです。 – chow

+0

特にありません。リストビューのために、追加します。 \tアンドロイド:layout_height = "wrap_content" \tアンドロイド:layout_width = "fill_parent" \tアンドロイド:layout_below = "@のID/top_linear_layout_id" \tアンドロイド:layout_above = "@ + ID/bottom_linear_layout_id" を線形レイアウトのそれぞれのIDと一緒に。 – Estel

0

問題は、それらのコンテンツのサイズに関連して両方を定義していることですが、両方のコンテンツの合計が画面より大きい場合は、一方が画面の上に重なる必要があります線形レイアウトで絶対測定を使用してlayout_heightを定義する方が良いでしょう。

3

あなたが探しているものがあります。 EstelはRelativeLayoutで正しい軌道に乗っています(ただし、LinearLayoutで行うことができますが、RelativeLayoutのアプローチはより洗練されています) しかし、レイアウトが狂っています Nevermind、間違っていたEstelのコメントを確認してください。 :)あなたは最初にあなたのヘッダーを定義し、それを一番上に整列させる必要があります。次に、フッターを定義し、それを一番下に揃えます。最後に、あなたのリストビューを宣言し、それをfill_parentの高さを与え、ヘッダフッタの上方と下方にレイアウトするためにそれを設定します。RelativeLayoutのアドバイスや方向のため

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:alignParentTop="true" 
     > 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:alignParentBottom="true" 
     > 
    </LinearLayout> 

    <ListView 
     android:id="@+id/listview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/footer" 
     android:layout_below="@id/header" 
     /> 
</RelativeLayout> 
+0

この場合、注文はどれくらい問題になりますか?いずれのウィジェットの配置にも重複がないことを明示的に確認していますが、描画順序がますます冗長になることはありませんか? – Estel

+0

ここをクリックしてください:http://developer.android.com/guide/topics/ui/index.html#ViewHierarchyレイアウトが順序通りに解析されていることを示します。したがって、フッターレイアウトの前にListViewが宣言されている場合は、ヘッダーの下から画面の下まですべてのスペースが必要です。 ListViewは解析されたときにフッターを認識しないため、フッターはListViewの上に描画されます。私はAndroid 2のそれを読んだと言いたい。2、注文はもはや重要ではありません(ただし、以前のバージョンをターゲットにしている場合でもそうです)が、今は明確な参照を見つけることができません。 – kcoppock

+0

私はhttp://developer.android.com/resources/articles/ui-1.6.htmlが見つかったということは、ツリーの下側でさらに宣言されているリソースへの前方参照を有効にしているということです。あなたはこれを参考にしていますか? – Estel

0

おかげですべてを。私は今それを修正することができます。

私はListViewコントロールの前にフッターのLinearLayoutを定義し、アンドロイドとしてリストビューを定義する必要があり

:layout_alignParentTop = "真" とAndroidを:layout_above = "@のID /フッター"

<?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" 
> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
    > 
     <TextView 
      android:textSize="12px" 
      android:text="something here" 
      android:layout_width="50px" 
      android:layout_height="wrap_content" 
      /> 
     <TextView 
      android:textSize="12px" 
      android:text="something here" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
     /> 
    </LinearLayout> 
    <RelativeLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
    > 
     <LinearLayout 
      android:id="@+id/footer" 
      android:orientation="horizontal" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:layout_alignParentBottom="true" 
     > 

      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12px" 
       android:text="50%" 
       /> 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12px" 
       android:text="50%" 
      /> 

     </LinearLayout> 
     <ListView 
      android:id="@+id/tablebody" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_above="@id/footer" 
     /> 
    </RelativeLayout> 
</LinearLayout> 
0

これは間違いなくあなたの問題を解決します:

<?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"> 
    <HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
      <TextView 
       android:textSize="12sp" 
       android:text="something here" 
       android:layout_width="50dp" 
       android:layout_height="wrap_content"/> 
      <TextView 
       android:textSize="12sp" 
       android:text="something here" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"/> 
     </LinearLayout> 
    </HorizontalScrollView> 
    <ListView 
     android:id="@+id/listbody" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"/> 
    <HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent"> 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12sp" 
       android:text="50%"/> 
      <TextView 
       android:layout_height="wrap_content" 
       android:layout_width="0dip" 
       android:layout_weight="1" 
       android:textSize="12sp" 
       android:text="50%"/> 
     </LinearLayout> 
    </HorizontalScrollView> 
</LinearLayout> 
関連する問題