I want to acheive the following. Transparent background with white tick 如何获得透明背景上的白色刻度线。 我尝试了以下。
viewprev = mgridview.getChildAt(i - mgridview.getFirstVisiblePosition());
viewprev.setBackgroundColor(Color.WHITE);
viewprev.setAlpha(0.5f);
答案 0 :(得分:1)
尝试一下
<?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>
您的刻度应在FrameLayout
中,应像代码中那样受约束,因此它始终位于ImageView
的中间。从图像中,我想您正在尝试长按以选择项目种类的东西。如果是这样,只需将xml中FrameLayout
的可见性设置为gone
,在LongClick事件中将其可见性设置为visible
这是上面代码的输出:
您可以尝试使用颜色来达到所需的透明度
答案 1 :(得分:0)
您可能需要使用FrameLayout.Framelayout包含您的图像和其上方的空ImageView。当您需要绘制刻度时,只需将其图像设置到该ImageView中即可。
答案 2 :(得分:0)
首先,您需要向网格项目布局中添加ImageView
。记住要在主网格图像下方插入xml标签,以便显示在顶部。然后使用match_parent
作为图像视图的宽度和高度,并将scaleType
分配到中心。这是您的复选标记视图。您可以添加半透明的背景,以在网格项目图像上方添加阴影,并且src
属性进入复选标记。
您还可以修改图像视图的可见性以切换对勾标记项目的隐藏和显示。