我正在为我的应用程序小部件实现一个小部件透明度选项,尽管我在修复十六进制颜色值时遇到了一些麻烦.作为十六进制颜色透明度的全新,我搜索了一下,虽然我找不到我的问题的具体答案.
我想用十六进制颜色设置透明度,所以让我说我的十六进制颜色ID"#33b5e5",我希望它是50%透明.然后我会使用"#8033b5e5",因为80%是50%.
我在这里找到了一个有用的图表:http://www.dtp-aus.com/hexadeci.htm.有了这些数据,我设法得到了这个:
0% = #00
10% = #16
20% = #32
30% = #48
40% = #64
50% = #80
60% = #96
70% = #112
80% = #128
90% = #144
Run Code Online (Sandbox Code Playgroud)
现在,当我以十六进制高于100时问题开始出现.十六进制颜色代码只能长8个符号吗?例如#11233b5e5(80%)崩溃.
我能做些什么才能让我使用更高的数字呢?
我试图实现这样的目标,我以这种方式在 xml 中使用了图层列表:
<item>
<shape android:shape="rectangle" >
<gradient
android:centerColor="#4DD0E1"
android:endColor="#76FF03"
android:startColor="@color/colorPrimary"
android:type="linear" />
</shape>
</item>
<item
android:bottom="2dp"
android:left="2dp"
android:right="2dp"
android:top="2dp">
<shape android:shape="rectangle" >
<solid android:color="#fff" />
</shape>
</item>
Run Code Online (Sandbox Code Playgroud)
这里是布局代码,形状的边框需要与图像重叠。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="12dp"
android:background="@android:color/transparent">
<ImageView
android:layout_width="100dp"
android:layout_height="75dp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginRight="12dp"
android:id="@+id/goals_image" />
<FrameLayout
android:id="@+id/goals_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:clickable="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="32dp"
android:background="#00000000"
>
<TextView
android:id="@+id/goals_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:text="Lose Weight"
android:textColor="@color/black"
android:layout_margin="40dp"
/>
</FrameLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但是如果我将背景设置为透明,则形状背景就会变成整个渐变色。如何实现具有透明背景的渐变笔触?提前致谢。
我有一种情况,我想添加一个与此应用程序效果相同的图像视图

正如您所注意到的,有一个 drawable 或一些隐藏在视图底部的东西,添加了一个透明的渐变。我怎样才能达到同样的效果?
我是android开发的新手。我的目标是设置渐变透明色的背景图片,我尝试了很多方法,但我无法实现这一目标。有人可以帮助我吗?。我附上了示例屏幕截图。
源代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:background="@drawable/bc"
android:orientation="vertical"
android:paddingLeft="20dp"
android:alpha="0.7"
android:id="@+id/about"
android:paddingRight="20dp"
android:paddingTop="60dp">
<android.support.design.widget.TextInputLayout
android:id="@+id/otp_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/hintStyle">
<EditText
android:id="@+id/mobNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_mob"
android:inputType="number"
android:singleLine="true"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="@color/colorPrimary"
android:text="@string/submit"
android:textColor="@android:color/white"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
提前谢谢。