简体   繁体   English

如何用半透明视图覆盖ImageView?

[英]How can I overlay an ImageView with translucent views?

I have an ImageView in an activity that takes up the whole screen. 我在一个占用整个屏幕的活动中有一个ImageView。 What I want to do is have a few translucent buttons in the corner of this ImageView overlayed on top (like 30% transparency). 我想做的是在此ImageView的角上有一些半透明的按钮,该按钮叠加在顶部(例如30%的透明度)。 Is this possible with an ImageView in android? 这可能与Android中的ImageView一起使用吗? If it is can someone point me in the right direction to get started? 如果可以,有人可以指出正确的方向开始学习吗?

Use a layout, and make your ImageView and two Buttons children within the layout. 使用一种布局,并使您的ImageView和两个Buttons子级在布局中。

Example using RelativeLayout: 使用RelativeLayout的示例:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ImageView
            android:src="@drawable/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:alpha="0.5"
            android:text="Button 1"/>

    <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/button1"
            android:alpha="0.5"
            android:text="Button 2"/>

</RelativeLayout>

You can position your buttons better by using android:layout_marginTop and android:layout_marginLeft attributes. 您可以使用android:layout_marginTop和android:layout_marginLeft属性更好地放置按钮。

The key parts to understand here are: 这里要理解的关键部分是:

1/ The ImageView is set to match_parent , therefore it'll stretch to fill the RelativeLayout. 1 / ImageView设置为match_parent ,因此它将拉伸以填充RelativeLayout。

2/ By default, sub Views are positioned at the top left of RelativeLayouts, this is why button1 appears there. 2 /默认情况下,子视图位于RelativeLayouts的左上方,这就是button1出现在其中的原因。

3/ Button2 is positioned to the right of button1 using the RelativeLayout attribute layout_toRightOf . 3 /使用RelativeLayout属性layout_toRightOf将Button2定位在button1的右侧。 Its vertical position is still set to the default - top. 其垂直位置仍设置为默认值-top。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android-如何在半透明的帮助叠加布局中突出显示位于布局下方的按钮? - Android - How can I highlight a button which is part of the layout underneath in an help overlay layout that is translucent? 半透明叠加在不同的视图上显示不同的效果 - Translucent overlay shows different effects on different views 如何在Android中的ImageView的半透明背景上获得纯文本? - How do I get solid text on a translucent background on a ImageView in Android? 如何在Android上实现滑动的叠加视图? - How can I implementing sliding, overlay views on Android? 如何在图库上叠加imageview? - How to overlay imageview on gallery ? 如何将ProgressBar叠加在圆形ImageView上,并使ProgressBar完全匹配尺寸? - How can I overlay a ProgressBar on top of a circular ImageView and have the ProgressBar match the dimensions exactly? 如何将 Imageview 保存在 imageview[] 中 - how can I make Imageview saved in imageview[] 如何与半透明Android应用程序背后的元素进行交互? - How can I interact with elements behind a translucent Android app? 我们如何在不改变现有设置的情况下修复透明/半透明视图上的高程阴影? - How can we fix the elevation shadows on transparent/translucent Views without changing the existing setup? 如何在 Android 中的其他布局上显示半透明图像? - How can I display Translucent Image over Other Layout in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM