studio objetos mover linearlayout layout_width examples ejemplos dinamico constraint centrar boton java android layout view

java - linearlayout - mover objetos en android studio



Android superpuesto a una vista ontop de todo? (5)

He intentado los awnsers antes, pero esto no funcionó. Ahora usé LinearLayout en lugar de TextureView, ahora funciona sin problemas. Espero que ayude a otros que tienen el mismo problema. :)

view = (LinearLayout) findViewById(R.id.view); //this is initialized in the constructor openWindowOnButtonClick(); public void openWindowOnButtonClick() { view.setAlpha((float)0.5); FloatingActionButton fb = (FloatingActionButton) findViewById(R.id.floatingActionButton); final InputMethodManager keyboard = (InputMethodManager) getSystemService(getBaseContext().INPUT_METHOD_SERVICE); fb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // check if the Overlay should be visible. If this value is false, it is not shown -> show it. if(view.getVisibility() == View.INVISIBLE) { view.setVisibility(View.VISIBLE); keyboard.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); Log.d("Overlay", "Klick"); } else if(view.getVisibility() == View.VISIBLE) { view.setVisibility(View.INVISIBLE); keyboard.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY); }

¿Puedes superponer una vista sobre todo en Android?

En iPhone obtendría la nueva vista estableciendo su frame.origin a (0,0) y su ancho y alto al ancho y alto de self.view . Al self.view a self.view se self.view como una superposición, cubriendo el contenido subyacente (o si tenía un fondo transparente y luego mostraba la vista detrás).

¿Hay una técnica similar en Android? Me doy cuenta de que las vistas son ligeramente diferentes (hay tres tipos (o más ...) relativelayout, linearlayout y framelayout), pero ¿hay alguna manera de simplemente superponer una vista sobre todo indiscriminadamente?


La mejor manera es ViewOverlay . Puede agregar cualquier dibujado como superposición a cualquier vista como su superposición desde Android JellyBeanMR2 (Api 18).

Agregue mMyDrawable a mMyView como su superposición:

mMyDrawable.setBounds(0, 0, mMyView.getMeasuredWidth(), mMyView.getMeasuredHeight()) mMyView.getOverlay().add(mMyDrawable)


Puedes usar bringToFront :

View view=findViewById(R.id.btnStartGame); view.bringToFront();


Simplemente use RelativeLayout o FrameLayout . La vista del último hijo se superpondrá a todo lo demás.

Android admite un patrón que Cocoa Touch SDK no tiene: administración de diseño.
El diseño para iPhone significa colocar todo absoluto (además de algunos factores de strech). El diseño en Android significa que los niños se colocarán en relación entre sí.

Ejemplo (segundo EditText cubrirá completamente el primero):

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/root_view"> <EditText android:layout_width="fill_parent" android:id="@+id/editText1" android:layout_height="fill_parent"> </EditText> <EditText android:layout_width="fill_parent" android:id="@+id/editText2" android:layout_height="fill_parent"> <requestFocus></requestFocus> </EditText> </FrameLayout>

FrameLayout es una especie de pila de vista. Hecho para casos especiales.

RelativeLayout es bastante poderoso. Puede definir reglas como Vista A tiene que alinear el diseño principal de la parte inferior , Vista B tiene que alinear A abajo , arriba , etc.

Actualización basada en comentarios

Por lo general, configura el contenido con setContentView(R.layout.your_layout) en onCreate ( onCreate el diseño por usted). Puede hacerlo manualmente y llamar a setContentView(inflatedView) , no hay diferencia.

La vista en sí misma podría ser una vista única (como TextView ) o una jerarquía de diseño compleja (diseños anidados, ya que todos los diseños son vistas).

Después de llamar a setContentView su actividad sabe cómo se ve su contenido y puede usar (FrameLayout) findViewById(R.id.root_view) para recuperar cualquier vista en esta jerarquía (Patrón general (ClassOfTheViewWithThisId) findViewById(R.id.declared_id_of_view) ).


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/root_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:id = "@+id/Everything" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- other actual layout stuff here EVERYTHING HERE --> </LinearLayout> <LinearLayout android:id="@+id/overlay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" > </LinearLayout>

Ahora cualquier vista que agregue en LinearLayout con android:id = "@+id/overlay" aparecerá como superposición con gravedad = derecha en Diseño lineal con android:id="@+id/Everything"