2016-07-02 9 views
0

Wie bringt man dieses Layout in Scroll-Form? Ich habe ScrollView verwendet, aber es war keine Hilfe. Es gab eine Ausnahme.Wie man den Effekt des Scrollens auf meine Aktivität bringt

Ich bin neu in Android. Würden Sie mir zeigen, welche Art von Berichtigung erforderlich ist?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.exampl.home.mydisplaybill.MainActivity"> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Select the IceCream flavor you want to order!" 
    android:id="@+id/textView" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true"`enter code here` 
    android:layout_alignParentStart="true" 
    android:textSize="20sp" 
    android:textStyle="bold" 
    android:textColor="#1199CC"/> 

<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=" Vanilla for Rs30" 
    android:textColor="#FF6352" 
    android:textStyle="bold" 
    android:id="@+id/checkBox" 
    android:layout_below="@+id/textView" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="30dp" 
    android:textSize="15sp" /> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView" 
    android:layout_alignBottom="@+id/checkBox" 
    android:layout_alignRight="@+id/textView" 
    android:layout_alignEnd="@+id/textView" 
    android:layout_marginRight="22dp" 
    android:layout_marginEnd="22dp" 
    android:src="@drawable/vanilla"/> 

<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=" Butterscotch for Rs40" 
    android:id="@+id/checkBox2" 
    android:textColor="#FF6352" 
    android:textStyle="bold" 
    android:layout_below="@+id/checkBox" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="69dp" 
    android:textSize="15sp"/> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView2" 
    android:layout_alignBottom="@+id/checkBox2" 
    android:layout_alignRight="@+id/imageView" 
    android:layout_alignEnd="@+id/imageView" 
    android:src="@drawable/butterscotch" 
    /> 

<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=" Pineapple for Rs40" 
    android:id="@+id/checkBox3" 
    android:layout_below="@+id/checkBox2" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="69dp" 
    android:textColor="#FF6352" 
    android:textStyle="bold" 
    android:textSize="15sp"/> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView3" 
    android:layout_alignBottom="@+id/checkBox3" 
    android:layout_alignRight="@+id/imageView" 
    android:layout_alignEnd="@+id/imageView" 
    android:src="@drawable/pineapple1"/> 
<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text=" Pista for Rs50" 
    android:id="@+id/checkBox4" 
    android:layout_below="@+id/checkBox3" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="69dp" 
    android:textColor="#FF6352" 
    android:textStyle="bold" 
    android:textSize="15sp"/> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView4" 
    android:layout_alignBottom="@+id/checkBox4" 
    android:layout_alignRight="@+id/imageView" 
    android:layout_alignEnd="@+id/imageView" 
    android:src="@drawable/pista1"/> 
<CheckBox 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text=" Mixedfruit for Rs60" 
android:id="@+id/checkBox5" 
android:layout_below="@+id/checkBox4" 
android:layout_alignParentLeft="true" 
android:layout_alignParentStart="true" 
android:layout_marginTop="69dp" 
android:textColor="#FF6352" 
android:textStyle="bold" 
android:textSize="15sp"/> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView5" 
    android:layout_alignBottom="@+id/checkBox5" 
    android:layout_alignRight="@+id/imageView" 
    android:layout_alignEnd="@+id/imageView" 
    android:src="@drawable/fruitmix"/> 
<CheckBox 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text=" Brownie for Rs80" 
android:id="@+id/checkBox6" 
android:layout_below="@+id/checkBox2" 
android:layout_alignParentLeft="true" 
android:layout_alignParentStart="true" 
android:layout_marginTop="69dp" 
android:textColor="#FF6352" 
android:textStyle="bold" 
android:textSize="15sp"/> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView6" 
    android:layout_alignBottom="@+id/checkBox3" 
    android:layout_alignRight="@+id/imageView" 
    android:layout_alignEnd="@+id/imageView" 
    android:src="@drawable/brownie"/> 

+0

Welche Ausnahme wurde ausgelöst? Bitte posten Sie die Logcat und Ihren Code mit der Scrollview – babadaba

+0

Geben Sie den vollständigen Code Ihrer XML-Datei sowie Logcat Fehler und wenn möglich dann Java-Side-Code. @ Anshul – TapanHP

+0

@Tapanparmar: Ich habe Ihre Bearbeitung abgelehnt - das ist viel zu viel von a ändern Sie diesen Code. Es ist in Ordnung, zu säubern, aber nicht umzuschreiben. – halfer

Antwort

0

Schauen Sie dies hilfreich sein wird für Sie sein könnten: https://stackoverflow.com/a/6674387/5476209

Sie haben Ihre Hauptkomponente Scroll in Ihrem Layout XML-Datei zu setzen und sicher sein, dass Sie müssen ein einzelnes Kind In ihm ScrollView wird nicht mit mehreren Kind arbeiten, so nehmen Sie ein relatives oder lineares Layout als Eltern setzen Sie alle Ihren Code darin und dann ScrollView als Eltern aller Layouts.

Zuerst verstehen Konzepte und bitte stellen Sie zumindest Fragen, nachdem Sie nicht ähnliche Fragen wie es bekommen. Auch ich fand a useful blog here, also bitte gehen Sie es durch.

1

Setzen Sie die gesamte Textansicht und das Kontrollkästchen im relativen Layout oder linearen Layout. Wenn Sie dann das relative Layout oder das lineare Layout in die Scroll-Ansicht einfügen, funktioniert es. Die Scroll-Ansicht funktioniert nur, wenn nur ein Kind vorhanden ist und Sie mehrere untergeordnete Elemente haben. Deshalb gibt es einen Fehler.

Ich hoffe, diese Antwort wird Ihnen helfen.