我想达到下面提供的图像中看到的效果.....可能吗?
我知道如何进行渐变,并且知道如何将 imagebuttons src/bg 设置为可绘制对象,但我不知道从哪里开始同时拉出两者。
我想达到下面提供的图像中看到的效果.....可能吗?
我知道如何进行渐变,并且知道如何将 imagebuttons src/bg 设置为可绘制对象,但我不知道从哪里开始同时拉出两者。
它实际上非常简单。为了避免通过分层一堆视图来避免过度绘制,只需添加一个ColorFilter
到您的ImageView
:
imageView.setColorFilter(Color.parseColor("#994dace3"), PorterDuff.Mode.SRC_OVER);
没有添加过度绘制,您可以设置任何您想要的颜色,并尝试不同的 PorterDuff 混合模式。
例子:
我知道如何做渐变,我知道如何将 imagebuttons src/bg 设置为可绘制但我不知道从哪里开始同时拉出两者
我认为您所说的 agradient
实际上是一种设置了透明度值的颜色。据我所知,您正在寻找这样的东西:
您可以使用以下布局实现此目的:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/the_picture"
android:src="@color/transparent_color" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Message!" />
</RelativeLayout>
RelativeLayout
用于定位TextView
. _ ImageButton
被Picture
设置为背景。src
设置为透明度值介于00
(完全透明)和ff
(完全不透明)之间的颜色(任何颜色)。在上图中,我使用了70
. 因此,假设您选择 Green(#00ff00),为其添加透明值:#7000ff00 并将其添加到res/values/colors.xml
. 您也可以像我在下面所做的那样直接使用它。
这是上图中活动的完整 xml 代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/original" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/original"
android:src="#7000ff00" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Optional Message!"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="25sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
您可以在代码中为 TextView 设置自定义字体(如您提供的图片所示)。