android标头不透明度

android标头不透明度,android,header,opacity,Android,Header,Opacity,我正试图用透明的标题构建类似的listView,如下所示 但如何更改标题不透明度? 我试着在颜色代码中使用alpha,比如:“#00bebebe”,但这不起作用 我的标题背景“标题栏背景” 但只有当我不在其他版面中包含该版面时,它才会起作用。但是,当我在另一个页面中包含该布局时,如何设置不透明度呢?(如上面我的xml布局)只需通过标题的id找到标题布局,然后执行以下操作: LinearLayout headerLayout = (LinearLayout)findViewById(R.id.la

我正试图用透明的标题构建类似的listView,如下所示 但如何更改标题不透明度? 我试着在颜色代码中使用alpha,比如:“#00bebebe”,但这不起作用

我的标题背景“标题栏背景”


但只有当我不在其他版面中包含该版面时,它才会起作用。但是,当我在另一个页面中包含该布局时,如何设置不透明度呢?(如上面我的xml布局)

只需通过标题的id找到标题布局,然后执行以下操作:

LinearLayout headerLayout = (LinearLayout)findViewById(R.id.layoutHeader); 
AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F);
alpha.setDuration(0); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
// And then on your layout
headerLayout.startAnimation(alpha);
LinearLayout mytransparentLayout = (LinearLayout) findViewById(R.id.transparentLayout);
mytransparentLayout.setAlpha(0.5f);
还有
视图。setAlpha()
;但它是从API级别11开始的

编辑:

我们假设您的布局在另一个布局中:

<RelativeLayout android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<ImageView ...
bla bla bla />

<LinearLayout android:id="@+id/transparentLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
... your views
</LinearLayout>
...some other views

</RelativeLayout>

通过id查找布局,并通过设置Alpha来更改不透明度。

我发现设置Alpha有助于更改不透明度。但问题是,若我在其他布局(NullPointerExc)中包含那个布局,我就不能这样做。你知道如何解决这个问题吗?你所需要的就是为你的布局指定一个id,即使它在n个其他布局中,然后按id找到它,然后应用AlphaAnimation或setAlpha()方法。请参阅我的编辑。
View backgroundImg = findViewById(R.id.mycustomLayout);
    Drawable background = backgroundImg.getBackground();
    background.setAlpha(40);
LinearLayout headerLayout = (LinearLayout)findViewById(R.id.layoutHeader); 
AlphaAnimation alpha = new AlphaAnimation(0.5F, 0.5F);
alpha.setDuration(0); // Make animation instant
alpha.setFillAfter(true); // Tell it to persist after the animation ends
// And then on your layout
headerLayout.startAnimation(alpha);
<RelativeLayout android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<ImageView ...
bla bla bla />

<LinearLayout android:id="@+id/transparentLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
... your views
</LinearLayout>
...some other views

</RelativeLayout>
LinearLayout mytransparentLayout = (LinearLayout) findViewById(R.id.transparentLayout);
mytransparentLayout.setAlpha(0.5f);