Android 如何把一个 RelativeLayout或ImageView背景设为透明

在项目中,需要把RelativeLayout 和  ImageView背景设置为透明,怎么实现呢?这里主要通过代码,请参阅以下关键代码:

public ImageView imgDetail;
private RelativeLayout rlMain;

rlMain= (RelativeLayout) findViewById(R.id.rlMain);//布局
imgDetail = (ImageView)findViewById(R.id.imgDetail); // 图片
//设置背景
rlMain.setBackgroundColor(Color.TRANSPARENT);
imgDetail.setBackgroundColor(Color.TRANSPARENT);

主要用到类 :

android.graphics.Color 和 android.view.View 类的setBackgroundColor方法!

拓展:

android中其他继承android.view.View 类,背景设置为透明的方法也类似!

时间: 2024-08-11 09:44:42

Android 如何把一个 RelativeLayout或ImageView背景设为透明的相关文章

Android openGL ES 2.0里Surfaceview背景透明

surfaceview的黑色背景会挡住其父的背景,现在把surfaceview的背景设为透明,既可以看到所绘的3D物体,又可以看到背景. 在onSurfaceCreated里,调用GLES20.glClearColor(0f, 0f, 0f, 0f);alpha为0,即透明. 然后,对surfaceview要作一定处理: mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);TestRenderer renderer = new TestRe

android如何写一个自定义的dialog可以在Title的位置弹出来

先上效果图: Title的Layout为: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="@dimen/title_h

Android SlideAndDragListView,一个可排序可滑动item的ListView

SlideAndDragListView简介 SlideAndDragListView,可排序.可滑动item显示”菜单”的ListView. SlideAndDragListView(SDLV)继承于Android的ListView,SDLV可以拖动item到SDLV的任意位置,其中包括了拖动item往上滑和往下滑:SDLV可以向右滑动item,像Android的QQ那样(QQ是向左滑),然后显现出来"菜单”之类的按钮. github地址:https://github.com/yydcdut/

Android ViewFlow的一个例子

完成这个例子的步骤: 1.下载ViewFlow的源码,然后将类ViewFlow放在自己的工程的src的某个包下. 2.下载的源码里有2个工程view flow,viewflow-example.将view flow工程里的attr 3.布局文件如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/

Android开发之自定义TabHost文字及背景(源代码分享)

使用TabHost 可以在一个屏幕间进行不同版面的切换,而系统自带的tabhost界面较为朴素,我们应该如何进行自定义修改优化呢 MainActivity的源代码 package com.dream.ledong; import android.app.TabActivity; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.Gr

android 设置背景为空(透明)

在给控件设置背景时像ps那样的背景透明 在3.0以下可以使用 imageView.setBackgroundResource(android.R.id.empty); 但是这个方法在3.0以上会出现 ERROR/AndroidRuntime(xxxxx): Caused by: android.content.res.Resources$NotFoundException: File  from drawable resource ID #0x1020004可以用imageview.setBac

Android 界面布局之RelativeLayout

Android 的 RelaliveLayout 布局的参数定义: android:layout_above="@id/xxx"  --将控件置于给定ID控件之上android:layout_below="@id/xxx"  --将控件置于给定ID控件之下 android:layout_toLeftOf="@id/xxx"  --将控件的右边缘和给定ID控件的左边缘对齐android:layout_toRightOf="@id/xxx&

android如何写一个循环文字滚动的TextView

效果图: 在layout中这样来声明: <com.kaixin001.view.ScrollText android:id="@+id/news_statustxt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="10dp" android:paddingRight="1

转 Android RadioButton设置选中时文字和背景颜色同时改变

主要应用在购物车,像淘宝的那样,点击以后弹出一个选择种类颜色这样的popuwindow以后,然后这个选择种类的地方要用到类似这个玩意儿. 搜了一下,效果和这个文章一致.转了. 原文地址:http://blog.csdn.net/liuwan1992/article/details/52688408 在使用 RadioButton 时,有时我们会想要达到选中时文字颜色和背景颜色同时改变的效果,这里还需要多进行几步操作. 首先,在布局文件中新建一组 RadioButton : [html] view