2012-04-11 93 views
2

我有< .ImageView>enter code here s(图标)在我的android布局xml文件中,它们包含在<ScrollView>中。需要有关Android固定页脚的线性布局帮助

例如,

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

对于这种布局,我想附加一个固定页脚。基本上一个小标签出现在屏幕的底部,即使我滚动到一路向下或一直到顶部时仍然保留。

回答

5

我倾向于写了这样的布局与孩子们LinearLayout作为根元素和权重动态分配屏幕资源。它使布局定义紧凑,不需要定义额外的ID。

<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为根元素,与位于“上面”的底端对齐页脚ScrollView,然而,可能是在性能方面略胜一筹,但我怀疑它就会在一个noticable不同像这样的简单视图层次结构的情况。 RelativeLayout方法确实需要分配一些id(至少对于页脚,我会说)。

+0

非常感谢,这正是我一直在寻找的。 – anonymous123 2012-04-11 13:24:41

+0

另外我想知道,如果我们使用相对布局,那么您的意思是更好的表现。 – anonymous123 2012-04-11 13:25:12

+0

布局权重需要一个小部件来测量两次。特别是当你开始用非零权重嵌套'LinearLayout'时,这是一件坏事,因为测量次数呈指数增长。这正是现今Lint工具在这些情况下向您显示警告的原因。通常(也是在这种情况下),您可以使用“RelativeLayout”实现相同的布局。如果你需要一个例子,我很乐意将它添加到上面的答案中。 – 2012-04-11 19:21:50

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>