studio programacion herramientas fundamentos con avanzado aplicaciones android scrollview relativelayout

android - programacion - Disposición relativa en ScrollView



manual de android en pdf (4)

Cuando utiliza ScrollView, debe saber que solo puede desplazarse cuando la altura de ScrollView es menor que la altura del hijo de ScrollView.
Para resolver este problema, puede definir la Altura de LinearLayout para match_parent, que es el único hijo de ScrollView. Luego defina la Altura de ScrollView en el código Java, como scrollView.getChildAt(0).getHeight() - 1; para asegurarse de que la altura de ScrollView sea menor que la altura del hijo de ScrollView
Para su propia respuesta, no es una buena manera de usar números mágicos en su código, como 427dp y 548dp.

Tengo un diseño relativo con varias "vistas de imagen" y cuando giro la pantalla, las vistas de imagen se desordenan ... así que decidí envolverlo en una vista de desplazamiento ... ¡¡pero la vista de desplazamiento no funciona! ¿Puede alguien ayudarme con eso? Sé que la forma correcta es diseñar una vista de cuadrícula o una vista de lista ... pero como tenía algunas preguntas y nadie me respondió en stackoverfloa, decidí seguir este camino. Aquí está mi código xml:

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


Experimenté el mismo problema con el diseño relativo en la vista de desplazamiento para solucionar este problema que rodea a mi diseño relativo con un diseño lineal, intente esto y también elimine la orientación del diseño relativo

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


Podría resolver mi pregunta con la ayuda de mi querido Ravi y un poco de cambio: el código es así:

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


Solución simple, solo agregue android: fillViewport = "true" a Scrollview como:

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