2016-08-11 5 views
0

Ich habe eine Frage, die ich keine Antwort finden konnte. Wie kann ich ein Layout scrollen und ein anderes Layout erstellen, das nicht scrollt? Auf der anderen Seite möchte ich ein Layout machen Einschließlich Einige Tasten, die bei Bedarf scrollt, und ich möchte zwei Tasten am unteren Rand des Bildschirms, und ich will nicht, dass sie beim Scrollen verschwinden.Wie scrolle ich einen Teil einer Aktivität

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:background="@drawable/background" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:context="com.myname.myapp.MainActivity"> 

    // a bunch of Buttons and TextViews 

    </RelativeLayout> 
</scrollView> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

     // two Moveless Buttons 

</RelativeLayout> 

Aber es funktioniert nicht.

+0

Was bedeutet "funktioniert nicht"? Was passiert, wenn Sie diese App ausführen und wie unterscheidet sie sich von dem, was Sie wollen? –

+0

Es hat Fehler. "Multiple Root Tags" – Skillson

+0

Googeln von Fehlermeldungen gibt fast immer gut. Zum Beispiel [http://stackoverflow.com/questions/24275533/multiple-root-tags-in-android-studio]. –

Antwort

3

Ihre ScrollView hat eine Breite und Höhe, die dem übergeordneten Element entspricht. Dies bedeutet, dass es den gesamten verfügbaren Platz einnimmt und nichts für das RelativeLayout übrig lässt. Wahrscheinlich möchten Sie das, was Sie bereits haben, in ein LinearLayout einfügen und dann das Attribut layout_weight verwenden, um den Bereich aufzuteilen.

+0

Ja. Es klappt. Danke vielmals. – Skillson

0

Ich bin mir nicht sicher, ob ich verstehe, was Sie tun möchten. Aber versuchen Sie dies und geben Feedback

(Codebeispiel nicht in Android Studio getestet)

  <?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
       > 
     <ScrollView 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:background="@drawable/background" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <RelativeLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        tools:context="com.myname.myapp.MainActivity"> 

       // a bunch of Buttons an TextViews 


       </RelativeLayout> 
      </ScrollView> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="80dp (for example)>" 
        android:layout_alignParentBottom="true"> 

        // two Moveless Buttons 

      </RelativeLayout> 
</RelativeLayout> 
+0

danke. Ihre Lösung funktioniert. genau was ich wollte. – Skillson

0

Machen Sie Ihre Wurzel eine vertikale Linearlayout mit einem Scrollview, die rollbaren Ansichten zu halten, und ein RelativeLayout, Ihre Tasten zu halten .

Sie können die Gewichtungsfähigkeit des LinearLayout nutzen, indem Sie ein Gewicht von 1 auf den Scrollview anwenden, so dass er so viel Platz wie möglich beansprucht, während das RelativeLayout die Größe Ihres größten Buttons hat. Hier

ein Beispiel:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ScrollView 
     android:background="@drawable/background" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      tools:context="com.myname.myapp.MainActivity"> 

     // a bunch of Buttons an TextViews 

     </RelativeLayout> 
    </ScrollView> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

      // two Moveless Buttons 

    </RelativeLayout> 
</LinearLayout> 

HTHS!

Verwandte Themen