Android的布局背景Alpha [英] Android Layout background alpha

查看:208
本文介绍了Android的布局背景Alpha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有我正在使用,以填补我的网页布局,我必须设置在我的绘制文件夹在布局召开的背景图像。

Hi I have a layout which I'm using to fill my page and I have to set a background image held in my drawable folder in that layout.

我要接盘 alpha值形象的东西相当低,几乎让像水标志的图像。

I want to then set the alpha value of the image to something quite low almost make the image like a water mark.

我的XML看起来像

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/main_background" >

正如你可以看到我分配了id的布局

As you can see I have assigned an id to the layout

我想在我的OnCreate我可以做这样的事情?

I thought in my oncreate I could do something like this?

View backgroundimage = (View) findViewById(R.id.background);
backgroundimage.setAlpha(80);

这是不工作但我怀疑它,因为我想投背景为查看我要抛弃它?

This is not working however I suspect its because I'm trying to cast the background as a View what should I cast it as?

推荐答案

尝试使用 Drawable.setAlpha();

Try to use Drawable.setAlpha();

你应该做的是这样的:

View backgroundimage = findViewById(R.id.background);
Drawable background = backgroundimage.getBackground();
background.setAlpha(80);

这篇关于Android的布局背景Alpha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆