简体   繁体   English

如何将图像保持在透明背景上?

[英]How do i keep image on transparent background?

I want to acheive the following. 我要实现以下目标。 Transparent background with white tick How do i get the white tick mark on the transparent background. 带有白色刻度线的透明背景我如何在透明背景上获得白色刻度线。 i tried the following. 我尝试了以下。

viewprev = mgridview.getChildAt(i - mgridview.getFirstVisiblePosition());
                viewprev.setBackgroundColor(Color.WHITE);
                viewprev.setAlpha(0.5f);

Try this out, 试试看

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

<ImageView
    android:id="@+id/ivMain"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:contentDescription="@string/app_name"
    android:src="@mipmap/ic_launcher"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<FrameLayout
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:background="#99676767"
    app:layout_constraintBottom_toBottomOf="@id/ivMain"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="@id/ivMain">

    <ImageView
        android:layout_width="55dp"
        android:layout_height="55dp"
        android:layout_gravity="center"
        android:contentDescription="@string/app_name"
        android:src="@drawable/vector_favorite" />
</FrameLayout>

Your tick should be in the FrameLayout which should be constrainted as in the code so its always in the middle of the ImageView . 您的刻度应在FrameLayout ,该FrameLayout应像代码中那样受到约束,因此它始终位于ImageView的中间。 From the image I guess you're trying to create a long click to select items kind of thing. 从图像中,我想您正在尝试长按以选择项目种类的东西。 If so just set the visibility of FrameLayout to gone in xml and in LongClick event set it to visible 如果是这样刚刚成立的知名度FrameLayoutgone在XML和LongClick事件将其设置为visible

This is the output of above code: 这是上面代码的输出:

产量

You can play around with the color to achieve your desired transparency level 您可以试用颜色以达到所需的透明度

You may need to use FrameLayout.The Framelayout contains your image and an empty ImageView above it. 您可能需要使用FrameLayout.Framelayout包含您的图像和其上方的空ImageView。 When you need to draw a tick - just set its image into that ImageView. 当您需要绘制刻度时,只需将其图像设置到该ImageView中即可。

First you need to add an ImageView to your grid item layout. 首先,您需要将ImageView添加到网格项目布局。 Remember to insert the xml tag below the main grid image in order to appear on top. 记住要在主网格图像下方插入xml标签,以便显示在顶部。 Then use match_parent as the image view width and height and assign the scaleType to center. 然后使用match_parent作为图像视图的宽度和高度,并将scaleType分配给中心。 This is your check mark view. 这是您的复选标记视图。 You can add a semi transparent background to make a shade above the grid item image and the src attribute goes to the check mark. 您可以添加半透明的背景,以在网格项目图像上方添加阴影,并且src属性进入复选标记。

You can also modify the image view visibility toggle hide and show of the check mark item. 您还可以修改图像视图的可见性切换对勾标记项目的隐藏和显示。

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

相关问题 如何从其他图像创建位图并保持透明背景? - How do I create Bitmap from another image and keep the transparent background? 我的单选按钮背景是透明的,如何使其不透明? - My radio button background is transparent, how do I make it opaque? 如何在透明ListView下放置背景? - How do I put a background under a transparent ListView? 如何在Android上使精灵的背景透明? - How do I make the background of a sprite transparent on Android? 如何保持后台服务始终在后台运行 - How do I keep Background Service always run in background 透明的背景imageview使它上面通常不透明的文本也透明。 我该如何解决? - The transparent background imageview makes the normally opaque text that comes on it also transparent. How do I fix this? 如何在活动中使背景图像透明? - How to make a background image transparent in the activity? 如何在透明背景后面的 FloatingActionButton 中居中图像? - How to center image in FloatingActionButton behind transparent background? 如何在代码中设置图像按钮的透明背景? - How to set transparent background for Image Button in code? 如何显示带有透明背景图像的弹出窗口? - how to display a popup windows with transparent background image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM