2012-04-05 20 views
0

Ich möchte, dass meine App horizontal scrollen kann, damit sie zwischen Seiten gleiten kann. Aber wenn ich diese Funktion bei Android SDK verwende, wird es mich nicht lassen das XML-Layout füllen Elternteil, d. H. Es wird nicht zulassen, dass ich einen vollständigen Bildschirm, um meine Schaltflächen und Objekte enthalten.Wie benutzt man HorizontalScrollView?

Irgendeine Idee, wie kann ich das beheben oder was ist eine alternative Methode?

Hier ist der Code:

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

    <RelativeLayout 
     android:layout_width="348dp" 
     android:layout_height="559dp" > 

     <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentLeft="true" 
      android:layout_marginBottom="341dp" 
      android:layout_marginLeft="146dp" 
      android:src="@drawable/ic_launcher" /> 

    </RelativeLayout> 


</HorizontalScrollView> 
+0

Es wäre schön, wenn Sie Ihren Code –

+0

hier hinzufügen Ja i hinzugefügt der Code ^^ – user1144349

+0

Mögliche Duplikat stackoverflow.com/ Fragen/5565949 –

Antwort

0

ändern die relative Layout Linearlayout. Ähnlich wie bei einer vertikalen ScrollView wird ein LinearLayout verwendet.

Hier ist ein Beispiel-Layout ich in einem meiner Projekte haben:

<HorizontalScrollView 
      android:id="@+id/horizontalScrollView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:scrollbars="none" > 

      <LinearLayout 
       android:id="@+id/LinearLayout1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="horizontal" > 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/class_tab" /> 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/exam" /> 

       <Button 
        android:id="@+id/button_more" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/more" /> 

      </LinearLayout> 
     </HorizontalScrollView> 
+0

Cool, aber wo sind alle Layout-Attribute für die Tasten und alles? – user1144349

+0

oh ich habe sie im style-Attribut hinzugefügt. lass mich das ändern. –

+0

Cool! und wie funktioniert das? Wenn ich es teste was genau passierte? – user1144349