2016-03-29 26 views
-1

Ich versuche, einen alternierenden Text und Bild in meiner Bildlaufansicht zu haben. Es gibt keine Fehler im Code, wenn ich versuche, die Anwendung auszuführen. Seine Kraft schließt sich. Ich bin neu in Android Studio. Wie kann ich das beheben? Ich habe versucht, Antworten hier zu suchen, aber ich kann scheinen, nicht die Lösung zu finden, nach der ich suche.Wechselnde Textansicht und Bildansicht in einer Bildlaufansicht

Hier ist mein Code

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

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:gravity ="center" 
       android:fillViewport="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginTop="0dp" 
       android:id="@+id/scrollView"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:textColor="#000" 
      android:textColorLink="@android:color/black" 
      android:textSize="18sp" 

      android:text="hello"/> 

     <ImageView 
      android:layout_width="15dp" 
      android:layout_height="15dp" 
      android:src="@drawable/cheese_1"/> 


     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:textColor="#000" 
      android:textColorLink="@android:color/black" 
      android:textSize="18sp" 
      android:text="hi" /> 

     <ImageView 
      android:layout_width="15dp" 
      android:layout_height="15dp" 
      android:src="@drawable/cheese_2"/> 

    </ScrollView> 

</LinearLayout> 
+1

folgt Ihre Java-Klasse und Ihr Logcat zu –

Antwort

0

Jetzt arbeiten sie

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

     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:gravity ="center" 
        android:fillViewport="true" 
        android:layout_alignParentStart="true" 
        android:layout_marginTop="0dp" 
        android:id="@+id/scrollView"> 

      <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 
      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center_vertical" 
       android:textColor="#000" 
       android:textColorLink="@android:color/black" 
       android:textSize="18sp" 
       android:text="hello"/> 

      <ImageView 
       android:layout_width="15dp" 
       android:layout_height="15dp" 
       android:src="@drawable/cheese_1"/> 


      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center_vertical" 
       android:textColor="#000" 
       android:textColorLink="@android:color/black" 
       android:textSize="18sp" 
       android:text="hi"/> 

      <ImageView 
       android:layout_width="15dp" 
       android:layout_height="15dp" 
       android:src="@drawable/cheese_2"/> 
    </LinearLayout> 
     </ScrollView> 

    </LinearLayout> 
+0

Danke, das hilft mir sehr. Und jetzt verstehe ich – Dreamer

0

Scroll kann darin nur ein Kind enthält. Setzen Sie also imageViews und TextViews in LinearLayout und setzen Sie dann LinearLayout in ScrollView.

+0

Vielen Dank für Ihre Antwort. – Dreamer

0

Sie haben enthalten zu viele direkte Kinder im Scroll-Ansicht. In der Scroll-Ansicht kann nur ein Kind zu einem bestimmten Zeitpunkt behandelt werden. Daher müssen Sie alle anderen Ansichten unter nur einer Ansicht umbrechen.

so Ihre xml wird nun wie folgt aussehen

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

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:gravity ="center" 
       android:fillViewport="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginTop="0dp" 
       android:id="@+id/scrollView"> 
    <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:textColor="#000" 
      android:textColorLink="@android:color/black" 
      android:textSize="18sp" 

      android:text="hello"/> 

     <ImageView 
      android:layout_width="15dp" 
      android:layout_height="15dp" 
      android:src="@drawable/cheese_1"/> 


     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:textColor="#000" 
      android:textColorLink="@android:color/black" 
      android:textSize="18sp" 
      android:text="hi" /> 

     <ImageView 
      android:layout_width="15dp" 
      android:layout_height="15dp" 
      android:src="@drawable/cheese_2"/> 
    </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

Das jetzt funktionieren sollte.

+0

Vielen Dank für Ihre Antwort. – Dreamer

2

stattdessen eine Listview oder Recyclerview verwenden und eine benutzerdefinierte Adapter haben, um Bild und Text alternativ zu zeigen. Das wäre viel besser und kontrollierbarer.

wenn Sie wollen immer noch nur verwenden Scroll Sie nur eine direkte Kind haben kann, eine lineare Layout als Kind von Scroll und alle Bild- und Textviews als Kinder zu diesem Linearlayout scrollview.Add als

Post
<ScrollView ..> 
    <LinearLayout ..> 
    <TextView ../> 
    <ImageView ../> 
    <TextView ../> 
</LinearLayout> 
</ScrollView> 
+0

Vielen Dank für Ihre Antwort. – Dreamer

Verwandte Themen