2013-09-07 13 views
24

Mam układ względny z wieloma "widokami obrazu", a gdy obracam się wokół ekranu, widoki obrazu stają się nieuporządkowane ... zdecydowałem się więc zawinąć je w widok przewijania ... ale widok przewijania nie " t działa !!! Czy ktoś może mi w tym pomóc? Wiem, że właściwą drogą jest zaprojektowanie gridview lub listview ... ale ponieważ miałem kilka pytań i nikt mi nie odpowiedział w stackoverfloa, zdecydowałem się pójść tą drogą. tu jest mój kodu xml:Układ względny w 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> 

Odpowiedz

19

przeżyłem sam problem z układem względna wewnątrz Scroll Widok do pokonania to ja owinięty wokół mojego względnego układu z układem liniowym, spróbuj tak i również usunąć orientację ze względnym układzie

<?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

zrobiłem swoje rozwiązanie i obliczu tak wielu błędów! nawet działanie nie pojawia się w ten sposób! :( –

+0

jaki jest błąd – Ravi

+0

Chciałem skopiować błędy i uruchomić aplikację ponownie ... zabawne, że teraz nie ma błędu, ale nie ma różnicy dla problemu! Mam nadal ten problem ... –

-4

mogę rozwiązać moje pytanie z pomocą drogiego Ravi i trochę zmian bitów: kod idzie tak:

<?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

Nie sądzę, że kodowanie wysokości jest drogą do zrobienia. –

1

Gdy używasz ScrollView, powinieneś wiedzieć, że możesz przewijać tylko wtedy, gdy wysokość ScrollView jest mniejsza niż wysokość potomka ScrollView.
Aby rozwiązać ten problem, można zdefiniować Wysokość liniowego odstępu dla elementu match_parent, który jest jedynym dzieckiem ScrollView. Następnie określ wysokość ScrollView w kodzie Java, na przykład scrollView.getChildAt(0).getHeight() - 1;, aby upewnić się, że wysokość ScrollView jest mniejsza niż wysokość potomka ScrollView.
Dla własnej odpowiedzi nie jest to dobry sposób na używanie magicznych liczb w kodzie, na przykład 427dp i 548dp.

22

Proste rozwiązanie, po prostu dodaj androida: fillViewport = "true" Scrollview jak:

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

<RelativeLayout ....... /> 

</ScrollView> 
+0

To wystarczy! Dzięki! :) – Marlon

Powiązane problemy