【发布时间】:2012-11-15 07:48:06
【问题描述】:
我正在尝试构建类似的带有透明标题的列表视图,例如Attaching a fixed, transparent, header to a ListView? 但是我怎样才能改变标题不透明度? 我尝试在颜色代码中使用 alpha,例如:“#00bebebe”,但没有奏效。
我的标题背景“title_bar_background”
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Top color -->
<item android:bottom="20dip">
<shape android:shape="rectangle">
<solid android:color="#bebebe"
/>
</shape>
</item>
<!-- Bottom color -->
<item android:top="20dip">
<shape android:shape="rectangle">
<solid android:color="#696969" />
</shape>
</item>
</layer-list>
我的标题布局“custom_title”
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
....
android:background="@drawable/title_bar_background"
android:id="@+id/customLayout"
>
还有我的 listView,其中我包含 custom_title
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
..... >
<include
layout="@layout/custom_title"
android:layout_height="40dip"
android:layout_width="fill_parent"/>
这项改变不透明度的工作
View backgroundImg = findViewById(R.id.mycustomLayout);
Drawable background = backgroundImg.getBackground();
background.setAlpha(40);
但只有当我不将该布局包含在其他布局中时它才有效。但是,当我在另一个布局中包含该布局时,我怎么能设法设置不透明度? (就像我上面的 xml 布局)
【问题讨论】: