2012-04-11 3 views
2

Ich habe < .ImageView>enter code here s (Symbole) in meinem Android-Layout-XML-Datei, die von einem <ScrollView> umfasst sind.Brauchen Sie Unterstützung mit Android festen Fußzeile für ein lineares Layout

Eg.

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

Zu diesem Layout möchte ich eine feste Fußzeile anhängen. Grundsätzlich eine kleine Registerkarte auf der Unterseite des Bildschirms, die bleibt auch wenn ich bis ganz nach unten oder ganz nach oben scrollen.

Antwort

5

Ich neige dazu, können versuchen, Layouts wie dies mit einem LinearLayout als Wurzelelement und Gewichte auf die Kinder zu schreiben dynamisch den Bildschirmstatus zuweisen Es hält die Layoutdefinition kompakt und erfordert keine Definition von zusätzlichen IDs.

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

ein RelativeLayout als Wurzelelement verwendet, wobei die ScrollView positionierte ‚oben‘ die untere justierte Fußzeile ist jedoch wahrscheinlich etwas besser in Bezug auf Leistung, obwohl ich es Zweifel wird in denen ein noticable verschiedenen machen Fall einer einfachen Ansichtshierarchie wie dieser. Der RelativeLayout-Ansatz erfordert die Zuweisung einiger IDs (zumindest für die Fußzeile, würde ich sagen).

+0

Vielen Dank das ist genau das, was ich gesucht habe. – anonymous123

+0

Auch ich wollte wissen, was meinst du genau durch bessere Leistung, wenn wir ein relatives Layout verwenden. – anonymous123

+0

Layoutgewichte erfordern, dass ein Widget zweimal gemessen wird. Vor allem, wenn Sie LineareLayouts mit Nicht-Null-Gewichten verschachteln, ist das eine schlechte Sache, da die Anzahl der Messungen exponentiell ansteigt. Genau deshalb zeigt Ihnen das Lint-Tool in diesen Fällen eine Warnung. Oft (und auch in diesem Fall) können Sie dasselbe Layout mit einem 'RelativeLayout' realisieren. Wenn Sie ein Beispiel benötigen, füge ich es gerne meiner obigen Antwort hinzu. –

1

so etwas wie dieses ..

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

U wie dies auch ..

<?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> 
Verwandte Themen