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


一、设置控件的透明度
方法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"这句话就好了
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值