2010-09-03 17 views
13

Tengo una miniatura de video y cuando hace clic en ella, el video comienza a reproducirse en el reproductor de YouTube. Esto funciona muy bien, pero no está tan claro que tengas que hacer clic en la miniatura para jugar, así que tengo una imagen de botón de reproducción que quiero dibujar sobre la miniatura en la esquina inferior derecha. ¿Cómo voy a hacer esto? Actualmente tengo la miniatura en un objeto Drawable y el botón de reproducción en mi directorio de recursos dibujables. Probé cosas con bitmaps y lienzos, pero es bastante difícil y no sé si este es el camino a seguir.Android: imagen sobre imagen

¡Muchas gracias! Erik

Respuesta

27

Uso FrameLayout relativa o:

<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> 
    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/thumbnail"/> 
    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/play" android:layout_alignParentBottom="true" android:layout_alignParentRight="true"/> 
</RelativeLayout> 

o

<FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> 
    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/thumbnail"/> 
    <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/play" android:layout_gravity="bottom|right"/> 
</FrameLayout> 
+0

Funciona muy bien, gracias! – Erik

+2

framelayout funcionó para mí, gracias también estaba confundido y estaba pensando en agregarlo programáticamente. – UMAR

+1

+1 Gracias amigo. Al principio usé 'FrameLayout' y tu solución funcionó para mí. Gracias amigo. – Sajmon

4

¿Qué pasa con el uso de un FrameLayout o una RelativeLayout apilar las vistas ..

Aquí sigue un código psaudo:

<FrameLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<com.yourpackage.VideoPlayer 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
></VideoPlayer> 

<!-- Adjust the layout position of the button with gravity, margins etc... --> 
<Button 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="bottom" 
android:text="Play" 
/> 

</FrameLayout> 
+0

Hm buena idea, sin necesidad de procesar la imagen en sí. Voy a probar esto. – Erik

+1

Gestionado para resolverlo con un FrameLayout de hecho. ¡Gracias! – Erik

+0

+1 para psaudo :) –

0

que utilizan RelativeLayout y funcionó para mí

<RelativeLayout 
    android:id="@+id/image_container" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.AppCompatImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scaleType="fitXY" 
     android:adjustViewBounds="true" 
     android:clickable="true" 
     android:layout_gravity="top" 
     android:maxHeight="400dp"/> 

    <ImageView 
     android:id="@+id/play" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/ic_menu_play_large" 
     android:layout_centerInParent="true" /> 

</RelativeLayout>