设置控件的透明度 ,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"这句话就好了
一、设置控件的透明度
方法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"这句话就好了
相关文章推荐
- RelativityLayout 子控件的几个常用的属性 android:layout_centerHorizontal="true"、 android:layout_centerVertical="true" 、android:layout_centerInParent="true"
- android:layout_centerInParent = "true"和 android:layout_gravity = "center"
- RelativeLayout中子控件的android:layout_centerVertical="true"失效问题分析
- Android学习笔记——解决设置了android:layout_alignParentBottom="true"的控件会被弹出的输入法顶上去的问题
- 设置android:layout_centerInParent属性的两种方式
- android Relativelayout 某控件设置layout_alignParentRight=true,整行不显示问题
- Android 技术总结(004)—— ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法
- include进来的控件无法用layout_alignParentBottom="true"
- Android中RelativeLayout各个属性 android:layout_alignParentLeft="true"找不到有时候
- listView 中relativeLayout 布局的 android:layout_alignParentBottom="true" 无效的解决办法
- 设置父控件的事件,需要去掉子控件的android:clickable="true" 属性。
- ScrollView里面嵌套子控件时设置 android:layout_width="match_parent"无效
- android:属性 layout_alignParentRight android:paddingRight layout_centerInParent(父类)
- android android:duplicateParentState="true" "false"
- android中关于scrollview内部组件android:layout_height="fill_parent"无效的解决办法
- Android问题:Unexpected text found in layout file: """
- listView 中relativeLayout 布局的 android:layout_alignParentBottom="true" 无效的解决办法
- Android ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法
- android:layout_width="match_parent"
- android android:duplicateParentState="true" "false"