2010-09-03 69 views
13

我有一個視頻縮略圖,當您點擊它時,視頻開始在YouTube播放器中播放。這很好,但不太清楚,你必須點擊縮略圖才能播放,所以我想要在右下角的縮略圖上繪製一個播放按鈕圖像。我會怎麼做呢?我目前有一個可繪製對象中的縮略圖和我的可繪製資源目錄中的播放按鈕。我嘗試了一下位圖和畫布,但這很難,我不知道這是否應該走。Android:圖片在圖片

非常感謝! 埃裏克

回答

27

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

<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

很好,謝謝! – Erik 2010-09-03 10:53:30

+2

framelayout爲我工作,謝謝我也困惑,並正在考慮以編程方式添加它。 – UMAR 2011-10-20 09:44:28

+1

+1感謝隊友。起初我使用了'FrameLayout',你的解決方案適用於我。謝謝哥們。 – Sajmon 2013-11-18 18:47:39

4

有關使用FrameLayoutRelativeLayout堆棧的意見..

這裏如下一些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

嗯好主意,不需要處理圖像本身。要試試這個。 – Erik 2010-09-03 09:36:23

+1

設法用FrameLayout來解決它。謝謝! – Erik 2010-09-03 10:53:50

+0

+1爲psaudo :) – 2011-08-04 15:35:50

0

我用的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>