fije el ancho y la altura como porcentaje en el diseño relativo
Me gustaría tener esto: un ViewPager superpuesto por 2 flechas
- ¿Cómo se elimina la línea / sombra del separador entre la barra de estado y la pantalla principal?
- Cuando getView () en ArrayAdapter se llama
- Agregar una autoridad de certificado mediante programación al mismo tiempo que mantiene certificados SSL de sistema de Android
- Error de Compilación NDK de Android NDK_PROJECT_PATH = nulo
- Seguridad de los recursos de la cadena
Y obtengo lo que quiero por este código. Sin embargo, recibí estas advertencias de pelusas:
- esta disposición es inútil (para las disposiciones falsas)
- los pesos anidados son malos para el rendimiento.
Me pregunto si hay una mejor manera de obtener esta interfaz de usuario como yo quiero.
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v4.view.ViewPager android:id="@+id/dialog_instruction_pager" android:layout_width="wrap_content" android:layout_height="wrap_content" > </android.support.v4.view.ViewPager> <!-- this LinearLayout overlays the ViewPager --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" > <!-- This is just the container for the left and right arrows , it is allocated with only 20% of screen height--> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight=".2" android:orientation="horizontal" > <!-- I want to align this to the left and set width only 5% of the parent --> <ImageButton android:id="@+id/instruction_dialog_left_arrow" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight=".05" android:background="?android:attr/selectableItemBackground" android:scaleType="fitCenter" android:src="@drawable/arrow_left_grey" /> <!-- This is the dummy layout, standing in the middle of 2 arrows so they can be align to the left and right of the parent --> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight=".8" > </LinearLayout> <!-- I want to align this to the right and set width only 5% of the parent--> <ImageButton android:id="@+id/instruction_dialog_right_arrow" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight=".05" android:background="?android:attr/selectableItemBackground" android:scaleType="fitCenter" android:src="@drawable/arrow_right_grey" /> </LinearLayout> </LinearLayout>
PS: ¿Hay algún diseño que permita alinear a los niños a la izquierda, derecha, abajo (como RelativeLayout) y también permite definir el ancho, la altura como porcentaje (como el atributo "weight" en LinearLayout)?
Gracias !
- No se puede resolver el símbolo c882c94be45fff9d16a1cf845fc16ec5
- EXCEPCIÓN FATAL: main java.lang.VerifyError: net.sourceforge.jtds.jdbc.TdsCore
- Archivo de descarga de Android de problemas de memoria
- Consulta sqlite de Android para que coincida con la columna que contiene el texto
- Unidad de pruebas de creación de una base de datos SQLite utilizando Spock y Robospock
- No se encontraron propiedades key.store y key.alias en build.properties
- ¿Cómo recibir mensajes de difusión de SignalR utilizando Microsoft Java-Client?
- ¿Cuál es el equivalente a un setInterval / setTimeout de JavaScript en Android / Java?
Try the below code and see whether it works, This code will get the layout what you have attached <?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" android:orientation="vertical" > <android.support.v4.view.ViewPager android:id="@+id/dialog_instruction_pager" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/theme_blue" > </android.support.v4.view.ViewPager> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerInParent="true" android:background="@drawable/ic_launcher" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerInParent="true" android:background="@drawable/ic_launcher" /> </RelativeLayout>
prueba esto
para evitar esta disposición es inútil (para los diseños falsos) u debe android:background="@android:color/transparent"
y agregar la vista dummy en esa disposición linear porque la disposición no debe estar vacía .
para evitar pesas anidadas son malas para el rendimiento añadir un niño de diseño lineal. y leer mis comentarios en el código
y agregó la disposición de los padres para la imageview
para hacer la imagen verticalmente centro
prueba este código
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.view.ViewPager android:id="@+id/dialog_instruction_pager" android:layout_width="wrap_content" android:layout_height="wrap_content"></android.support.v4.view.ViewPager> <!-- this LinearLayout overlays the ViewPager --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <!-- This is just the container for the left and right arrows , it is allocated with only 20% of screen height--> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight=".2" android:orientation="horizontal"> <!--child layout to avoid nested weight with `waighSum` property--> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:weightSum="100"> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="5" android:gravity="center_vertical" android:orientation="horizontal"> <!-- I want to align this to the left and set width only 5% of the parent --> <ImageButton android:id="@+id/instruction_dialog_left_arrow" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:scaleType="fitCenter" android:src="@drawable/icon_clock" /> </LinearLayout> <!-- This is the dummy layout, standing in the middle of 2 arrows so they can be align to the left and right of the parent --> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="90" android:background="@android:color/transparent">// this line also makes layout usefull <!-- dummy view becouse layout should not be empty --> <View android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="5" android:gravity="center_vertical" android:orientation="horizontal"> <!-- I want to align this to the right and set width only 5% of the parent--> <ImageButton android:id="@+id/instruction_dialog_right_arrow" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackground" android:scaleType="fitCenter" android:src="@drawable/icon_clock" /> </LinearLayout> </LinearLayout> </LinearLayout> </LinearLayout> </FrameLayout>
espero que funcione para ti
Google introdujo una nueva API llamada android.support.percent
1) PorcentajeRelativeLayout
2) PorcentajeFrameLayout
Añadir dependencia de compilación como
compile 'com.android.support:percent:23.1.1'
Puede especificar la dimensión en porcentaje para obtener ambos beneficios de RelativeLayout
y porcentaje
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"/> <TextView app:layout_widthPercent="40%" app:layout_heightPercent="40%" app:layout_marginTopPercent="15%" app:layout_marginLeftPercent="15%"/> </android.support.percent.PercentRelativeLayout/>
Intente usar RelativeLayout y después ajuste la imagen izquierda alignParentLeft y la imagen derecha alignParentRight
- No se puede resolver el método 'findViewById (int)' en Fragment
- Diferente ancho de diseño dentro de RecyclerView y LinearLayout normal