Android:图像覆盖图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3634496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:06:01  来源:igfitidea点击:

Android: Image over image

android

提问by Erik

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

我有一个视频缩略图,当你点击它时,视频开始在 YouTube 播放器中播放。

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.

我目前在 Drawable 对象中有缩略图,在我的 drawable 资源目录中有播放按钮。

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

我尝试了位图和画布的东西,但它很难,我不知道这是不是要走的路。

回答by Konstantin Burov

Use Relative or FrameLayout:

使用相对或 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>

回答by Vidar Vestnes

What about using a FrameLayoutor a RelativeLayoutto stack the views..

使用 aFrameLayout或 aRelativeLayout来堆叠视图怎么样..

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>

回答by Imdad

I used RelativeLayout and it worked for me

我使用了RelativeLayout,它对我有用

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