[英]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
如果是这样刚刚成立的知名度FrameLayout
到gone
在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.