2010-09-03 50 views
13

Tôi có hình thu nhỏ video và khi bạn nhấp vào đó, video sẽ bắt đầu phát trong trình phát YouTube. Điều này làm việc tuyệt vời, nhưng nó không phải như vậy rõ ràng rằng bạn phải bấm vào hình thu nhỏ để chơi, vì vậy tôi có một hình ảnh nút chơi mà tôi muốn vẽ trên hình thu nhỏ ở góc dưới bên phải. Làm thế nào tôi sẽ đi về điều này? Tôi hiện đang có hình thu nhỏ trong đối tượng Drawable và nút phát trong thư mục tài nguyên có thể kéo của tôi. Tôi đã thử công cụ với bitmap và canvas nhưng nó khá khó khăn và tôi không biết nếu đây là con đường để đi.Android: Hình ảnh qua hình ảnh

Cảm ơn rất nhiều! Erik

Trả lời

27

Sử dụng tương đối hoặc 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> 

hoặc

<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

Hoạt động tuyệt vời, cảm ơn! – Erik

+2

framelayout làm việc cho tôi, cảm ơn tôi cũng đã nhầm lẫn và đã suy nghĩ để thêm nó theo chương trình. – UMAR

+1

+1 Cảm ơn bạn đời. Lúc đầu, tôi đã sử dụng 'FrameLayout' và giải pháp của bạn làm việc cho tôi. Cảm ơn cậu. – Sajmon

4

gì về việc sử dụng một FrameLayout hoặc một RelativeLayout để ngăn xếp các quan điểm ..

Ở đây sau một số mã 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 ý tưởng tốt, không cần phải xử lý hình ảnh riêng của mình. Gonna thử cái này – Erik

+1

Được quản lý để giải quyết nó bằng FrameLayout. Cảm ơn! – Erik

+0

+1 cho psaudo :) –

0

tôi đã sử dụng RelativeLayout và nó làm việc cho tôi

<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> 
Các vấn đề liên quan