2013-09-07 7 views
24

Ich habe ein relatives Layout mit mehreren "Bildansichten" und wenn ich um den Bildschirm kehre, werden die Bildansichten ungeordnet ... also habe ich beschlossen, es in eine Bildlaufansicht zu verpacken ... aber die Bildlaufansicht funktioniert nicht t Arbeit !!! Kann mir irgendjemand dabei helfen? Ich weiß, dass der richtige Weg ist, eine Gridview oder Listview zu erstellen ... aber da ich einige Fragen hatte und niemand mir in stackoverfloa antwortete, entschied ich mich, diesen Weg zu gehen. hier ist mein xml-Code:Relatives Layout in ScrollView

<?xml version="1.0" encoding="utf-8"?> 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ScrollView01" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:scrollbars="none" > 


<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 


    <Button 
     android:id="@+id/continuePizza" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="continue" /> 

    <Button 
     android:id="@+id/finishP" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/continuePizza" 
     android:layout_alignParentLeft="true" 
     android:text="finish" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="16dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView1" 
     android:layout_marginLeft="18dp" 
     android:layout_toRightOf="@+id/imageView1" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView1" 
     android:layout_marginTop="18dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView3" 
     android:layout_centerVertical="true" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView3" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView5" 
     android:layout_marginTop="17dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView2" 
     android:layout_alignTop="@+id/imageView5" 
     android:layout_marginLeft="10dp" 
     android:src="@drawable/download" /> 
    <ImageView 
     android:id="@+id/imageView8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView7" 
     android:layout_alignTop="@+id/imageView3" 
     android:src="@drawable/download" /> 

</RelativeLayout> 

</ScrollView> 

Antwort

19

ich gleiches Problem mit Relative-Layout innerhalb Scroll-Ansicht erleben diese i um mein relatives Layout mit einem linearen Layout gewickelt zu überwinden, wie dies versucht und auch Orientierung von relativem Layout

entfernen
<?xml version="1.0" encoding="utf-8"?> 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ScrollView01" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true" 
android:scrollbars="none" > 

<LinearLayout android:layout_width="match_parent" 
android:layout_height="match_parent"> 


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


<Button 
    android:id="@+id/continuePizza" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:text="continue" /> 

<Button 
    android:id="@+id/finishP" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/continuePizza" 
    android:layout_alignParentLeft="true" 
    android:text="finish" /> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="16dp" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView1" 
    android:layout_marginLeft="18dp" 
    android:layout_toRightOf="@+id/imageView1" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageView1" 
    android:layout_marginTop="18dp" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView3" 
    android:layout_centerVertical="true" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/imageView3" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageView5" 
    android:layout_marginTop="17dp" 
    android:src="@drawable/download" /> 

<ImageView 
    android:id="@+id/imageView7" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView2" 
    android:layout_alignTop="@+id/imageView5" 
    android:layout_marginLeft="10dp" 
    android:src="@drawable/download" /> 
<ImageView 
    android:id="@+id/imageView8" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/imageView7" 
    android:layout_alignTop="@+id/imageView3" 
    android:src="@drawable/download" /> 

</RelativeLayout> 
</LinearLayout> 
</ScrollView> 
+0

Ich habe Ihre Lösung und konfrontiert so viele Fehler! selbst die Aktivität zeigt sich dadurch nicht! :( –

+0

was ist der Fehler – Ravi

+0

Ich wollte die Fehler kopieren und so die Anwendung erneut ausführen ... es ist lustig, dass es keinen Fehler gibt, aber keinen Unterschied für das Problem! Ich habe immer noch das Problem ... –

-4

ich meine Frage mit Hilfe lieber Ravi und ein wenig ändern lösen könnte: der Code geht wie folgt aus:

<?xml version="1.0" encoding="utf-8"?> 


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ScrollView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scrollbars="none" > 



     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="427dp" > 



<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="548dp" > 




    <Button 
     android:id="@+id/continuePizza" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="continue" /> 

    <Button 
     android:id="@+id/finishP" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/continuePizza" 
     android:layout_alignParentLeft="true" 
     android:text="finish" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="16dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView1" 
     android:layout_marginLeft="18dp" 
     android:layout_toRightOf="@+id/imageView1" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView1" 
     android:layout_marginTop="18dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView3" 
     android:layout_centerVertical="true" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/imageView3" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView5" 
     android:layout_marginTop="17dp" 
     android:src="@drawable/download" /> 

    <ImageView 
     android:id="@+id/imageView7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView2" 
     android:layout_alignTop="@+id/imageView5" 
     android:layout_marginLeft="10dp" 
     android:src="@drawable/download" /> 
    <ImageView 
     android:id="@+id/imageView8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView7" 
     android:layout_alignTop="@+id/imageView3" 
     android:src="@drawable/download" /> 

</RelativeLayout> 
</LinearLayout> 
</ScrollView> 
+2

Ich denke nicht, dass die Höhenabmessungen hardcoding ist der Weg zu gehen. –

1

Wenn Sie die ScrollView verwenden, sollten Sie wissen, dass Sie nur blättern können, wenn die Höhe von ScrollView kleiner als die Höhe von ScrollViews Child ist.
Um dieses Problem zu lösen, können Sie die Höhe von LinearLayout für match_parent definieren, das das einzige Kind von ScrollView ist. Definieren Sie dann die Höhe von ScrollView im Java-Code, z. B. scrollView.getChildAt(0).getHeight() - 1;, um sicherzustellen, dass die Höhe von ScrollView kleiner als die Höhe von ScrollViews Kind ist.
Für Ihre eigene Antwort, es ist keine gute Möglichkeit, magische Zahlen in Ihrem Code zu verwenden, wie 427dp und 548dp.

22

einfache Lösung, nur android hinzufügen: fillViewport = "true" zu Scroll wie:

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

<RelativeLayout ....... /> 

</ScrollView> 
+0

Dieser hat den Trick gemacht! Vielen Dank! :) – Marlon

Verwandte Themen