Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Image over image

Tags:

android

I have a video thumbnail and when you click on it, the video starts playing in the YouTube player.

This works, but It's not clear that you have to click on the thumbnail to play, therefore, I want to draw a play button image over the thumbnail in the bottom right corner. How would I go about this?

I currently have the thumbnail in a Drawable object and the play button in my drawable resource directory.

I tried stuff with bitmaps and canvas but it's quite hard and I don't know if this is the way to go.

like image 702
Erik Avatar asked Sep 03 '10 09:09

Erik


People also ask

What is Layer list in Android?

Layer list. A LayerDrawable is a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top. Each drawable is represented by an <item> element inside a single <layer-list> element.

Can you set an image to multiple ImageView can you display the same ImageView multiple times?

Multiple Views of an ImageYou can also set multiple views for an image in the same scene. The following program is an example that demonstrates how to set various views for an image in a scene in JavaFX. Save this code in a file with the name MultipleViews. java.


2 Answers

Use Relative or FrameLayout:

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

or

<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>
like image 70
Konstantin Burov Avatar answered Oct 11 '22 04:10

Konstantin Burov


What about using a FrameLayout or a RelativeLayout to stack the views..

Here follows some psaudo code:

<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>
like image 20
Vidar Vestnes Avatar answered Oct 11 '22 04:10

Vidar Vestnes