Android: изображение поверх изображения
У меня есть миниатюра видео, и когда вы нажимаете на нее, видео начинает воспроизводиться в плеере YouTube.
Это работает, но не ясно, что вы должны нажать на миниатюру для воспроизведения, поэтому я хочу нарисовать изображение кнопки воспроизведения поверх миниатюры в правом нижнем углу. Как бы я пошел по этому поводу?
В настоящее время у меня есть миниатюра в Drawable объекте и кнопка воспроизведения в моем каталоге ресурсов Drawable.
Я пробовал вещи с растровыми изображениями и холстом, но это довольно сложно, и я не знаю, так ли это.
Ответы
Ответ 1
Используйте Relative или 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>
Ответ 2
Как использовать FrameLayout
или RelativeLayout
для складывания представлений.
Здесь следует некоторый код 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>
Ответ 3
Я использовал 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>