2012-04-11 13 views
2

<ScrollView>に含まれている .ImageView>enter code here(アンドロイドレイアウトのxmlファイルにアイコンがあります。線形レイアウトのAndroid固定フッターのサポートが必要

例:

<.ScrollView><br> 
<.LinearLayout><br> 
<.ImageView> ...<./ImageView><br> 
<./LinearLayout><br> 
<./ScrollView> 

このレイアウトには、固定フッターを付けたいと思います。基本的には画面の下部に小さなタブがあり、スクロールしていっても上までずっとスクロールしていても残っています。このような

答えて

5

私は子供のルート要素としてLinearLayoutと重みで、このようなレイアウトを記述する傾向があります画面の不動産を動的に割り当てる。レイアウト定義をコンパクトに保ち、余分なIDを定義する必要はありません。私はそれが顕著で異なる作ってあげる疑うもののScrollViewが下揃えフッターの「上記の」位置で

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <ImageView ... /> 
      <ImageView ... /> 
      ... 
      <ImageView ... /> 

     </LinearLayout> 
    </ScrollView> 

    <!-- footer here --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
     ... 
    </LinearLayout> 
</LinearLayout> 

、ルート要素としてRelativeLayoutを使用して、しかし、パフォーマンスの面で、おそらく若干良いですこのような単純なビュー階層の場合。 RelativeLayoutのアプローチでは、いくつかのIDを割り当てる必要があります(少なくともフッターには、私は言っています)。

+0

ありがとう、これはまさに私が探していたものです。 – anonymous123

+0

また、相対レイアウトを使用すると、パフォーマンスが向上して正確に何を意味するのかを知りたかったのです。 – anonymous123

+0

レイアウトウェイトは、ウィジェットを2回測定する必要があります。特に、ゼロ以外の重みで 'LinearLayout'を入れ子にすると、測定数が指数関数的に増加するため、これは悪いことです。 Lintのツールでは、このような場合に警告が表示されます。しばしば(そしてこの場合でも)、あなたは 'RelativeLayout'を使って同じレイアウトを実現することができます。例が必要な場合は、私は上記の私の答えにそれを追加してうれしいです。 –

1

何か..

<.ScrollView> 
<.LinearLayout> 
<.ImageView> ...<./ImageView> 
<./LinearLayout> 
<./ScrollView> 
<LinearLayout> 
<-- your footer here --> 
</LinearLayout> 
0

Uもこのように試すことができます。..

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

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView6" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView7" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView14" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 
      <ImageView 
       android:id="@+id/imageView11" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView8" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 
      <ImageView 
       android:id="@+id/imageView12" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

      <ImageView 
       android:id="@+id/imageView9" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_launcher" /> 

     </LinearLayout> 
    </ScrollView> 

    <RelativeLayout 
     android:id="@+id/relativeLayout2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/blackbg" 
     android:layout_alignParentBottom="true" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:text="Button" /> 

    </RelativeLayout> 

</RelativeLayout> 
関連する問題