studio interfaz interfaces gridlayout formulario examples ejemplo diseƱo android user-interface android-layout

android - interfaz - botones debajo expandiendo scrollview



gridlayout android ejemplo (5)

Encontré este enlace que realmente me ayudó.

http://www.droidnova.com/layout-technique-static-elements-below-scrollview,123.html

Tengo algunas necesidades personalizadas muy específicas para una solución de teclado, lo que requiere que maneje la pantalla y el desmontaje del teclado por mi cuenta como un elemento de capa z en frameLayout. Utilizo la solución en ese enlace para lograr eso y cambiar el tamaño de scrollView al mismo tiempo. Los botones en la vista de desplazamiento se mueven al ras con la parte inferior de la pantalla para nivelar con la parte superior del teclado.

La clave es tener android: fillViewport = "true" en scrollView. A continuación, establece programáticamente el margen inferior de scrollView y el margen superior del elemento inferior en -height.

Aquí están mis dos métodos que lo manejan:

private void setMargins_noKeyboard() { ScrollView fieldsScroller = (ScrollView)findViewById(R.id.scroll_fields_view); FrameLayout keyboardFrame = (FrameLayout)findViewById(R.id.keyboard_root); int buttonsKeyboardSize = keyboardFrame.getHeight(); MarginLayoutParams frameParams = (MarginLayoutParams)keyboardFrame.getLayoutParams(); frameParams.setMargins(0, 0, 0, 0); MarginLayoutParams scrollParams = (MarginLayoutParams)fieldsScroller.getLayoutParams(); scrollParams.setMargins(0, 0, 0, 0); keyboardFrame.setLayoutParams(frameParams); fieldsScroller.setLayoutParams(scrollParams); } private void setMargins_keyboard() { ScrollView fieldsScroller = (ScrollView)findViewById(R.id.scroll_fields_view); FrameLayout keyboardFrame = (FrameLayout)findViewById(R.id.keyboard_root); int buttonsKeyboardSize = keyboardFrame.getHeight(); MarginLayoutParams frameParams = (MarginLayoutParams)keyboardFrame.getLayoutParams(); frameParams.setMargins(0, -buttonsKeyboardSize, 0, 0); MarginLayoutParams scrollParams = (MarginLayoutParams)fieldsScroller.getLayoutParams(); scrollParams.setMargins(0, 0, 0, buttonsKeyboardSize); keyboardFrame.setLayoutParams(frameParams); fieldsScroller.setLayoutParams(scrollParams); }

El diseño que intento implementar es (creo) bastante simple.

Un TextView se expande dependiendo de lo que hay dentro. Justo debajo hay dos botones (Aceptar / Cancelar).

Puedo hacer que los botones se peguen a la parte inferior de la pantalla y eso funciona bien. Pero me gustaría tener esos botones justo debajo de TextView. He intentado muchas cosas diferentes, pero aquí está mi último diseño:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ScrollView android:id="@+id/Scroll" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" > <TextView android:id="@+id/Text" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </ScrollView> <RelativeLayout android:id="@+id/buttons" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_below="@+id/Scroll" android:layout_above="@+id/bottom" > <LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent"> <Button android:id="@+id/ButtonOK" android:layout_height="80dp" android:layout_width="fill_parent" android:text="OK" android:layout_weight="1"/> <Button android:id="@+id/ButtonCancel" android:layout_height="80dp" android:layout_width="fill_parent" android:text="Cancel" android:layout_weight="1"/> </LinearLayout> </RelativeLayout> <LinearLayout android:id="@+id/bottom" android:layout_height="0px" android:layout_width="fill_parent" android:layout_alignParentBottom="true"/> </RelativeLayout>

La distribución lineal vacía al final es un intento (infructuoso) de evitar que la vista se extienda más allá de la parte inferior de la pantalla ...

En todo lo que probé, los botones están en la parte inferior de la pantalla o pasarían cuando el TextView sea demasiado grande.

Aquí hay un boceto de lo que estoy tratando de hacer:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RelativeLayout android:id="@+id/buttons" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_alignParentBottom="true" > <LinearLayout android:orientation="horizontal" android:layout_alignParentTop="true" android:layout_height="wrap_content" android:layout_width="fill_parent"> <Button android:id="@+id/ButtonOK" android:layout_height="80dp" android:layout_width="fill_parent" android:text="OK" android:layout_weight="1"/> <Button android:id="@+id/ButtonCancel" android:layout_height="80dp" android:layout_width="fill_parent" android:text="Cancel" android:layout_weight="1"/> </LinearLayout> </RelativeLayout> <ScrollView android:id="@+id/ScrollParent" android:layout_above="@id/buttons" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ScrollView android:id="@+id/Scroll" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" > <TextView android:id="@+id/Text" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </ScrollView> </RelativeLayout>

Espero eso ayude



Este xml está bien para mi aplicación:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/nameOfrecipe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10sp" android:layout_marginLeft="10sp" android:layout_alignParentTop="true" android:textSize="20sp" android:text="Name of ingredients" /> <TableLayout android:id="@+id/tableOfingredients" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/nameOfrecipe" android:layout_marginTop="40sp" android:layout_marginLeft="10sp" android:layout_marginRight="10sp" > </TableLayout> <RelativeLayout android:id="@+id/l" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tableOfingredients" > <Button android:id="@+id/addDirectionsB" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="Add..." /> <Button android:id="@+id/cancelDirectionsB" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_toRightOf="@id/addDirectionsB" android:text="Cancel" /> <ScrollView android:id="@+id/directionsScroll" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@id/addDirectionsB"> <EditText android:id="@+id/directionsET" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" > <requestFocus /> </EditText> </ScrollView> </RelativeLayout> </RelativeLayout>


¿El objetivo es tener un área desplazable que ocupe toda la página menos la cantidad que ocupan algunos botones en la parte inferior?

Si ese es el caso, puede usar LinearLayout en el nivel externo y hacer uso de las ponderaciones:

<LinearLayout android:layout_height="wrap_content" orientation="vertical"...> <ScrollView android:layout_height="0dp" android:layout_weight="1" .../> <LayoutWithButtons android:layout_height="wrap_content" ..../> </LinearLayout>