您的位置:首页 > 产品设计 > UI/UE

设置控件的透明度 ,android:layout_centerInParent="true" 失效

2014-05-14 19:20 549 查看

一、设置控件的透明度
方法1.设置颜色背景透明度:
在控件中使用以下属性:
android:background="#99454545"
前2位表示透明度:范围是00~~ff(以16进制表示的,00代表全透明,ff--代表不透明)
后六位表示颜色:
方法2.使用属性android:alpha="0.7"
此方法即可以让图片透明也可让背景颜色透明
(1).背景图片透明
android:background="@drawable/cate_arrow_click"
android:alpha="0.7"
(2).背景颜色透明:
android:background="#454545"
android:alpha="0.7"
但此方法有个问题,我在android2.3.5和2.3.7上运行并没有显示透明的效果,在android4.1上显示就有透明的效果,不知道是不是版本低了不支持属性android:alpha="0.7"。使用方法1在低版本上可以显示透明的效果。

二、android:layout_centerInParent="true" 失效
android:layout_centerInParent="true" :在relativelayout中不起作用时的原因:使用了其他位置属性,例如:在某个组件的右边啊。。。。
例如:

<RelativeLayout
android:id="@+id/cate_product_list_title"
android:layout_width="match_parent"
android:layout_height="50dp" >

<ImageButton
android:id="@+id/cate_product_list_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:background="@null"
android:src="@drawable/cate_back_no" />

<ImageButton
android:id="@+id/cate_product_list_kind_select"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="@+id/cate_product_list_kind"
android:background="@null"
android:src="@drawable/cate_arrow_unclick" />

<TextView
android:id="@+id/cate_product_list_kind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_toRightOf="@+id/cate_product_list_back"
android:text="高跟鞋"
android:textSize="19dp" />

<Button
android:id="@+id/cate_product_list_filter"
android:layout_width="60dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="7dp"
android:background="#FF34B3"
android:text="筛选"
android:textSize="19dp" />
</RelativeLayout>
使用了android:layout_toRightOf="@+id/cate_product_list_back" 导致android:layout_centerInParent="true" 不起作用
布局如下:



去掉 android:layout_toRightOf="@+id/cate_product_list_back"这句话就好了

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐