-1

ここのような透明なヘッダーで同様のlistViewを構築しようとしていますが、固定された透明なヘッダーをListViewに添付しますか? しかし、ヘッダーの不透明度を変更するにはどうすればよいですか? 「#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"
>

そして、custom_titleを含む私のlistView

<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レイアウトのように)

4

2 に答える 2

2

ID でレイアウトを検索し、アルファを設定して不透明度を変更します。

于 2015-11-02T06:34:02.053 に答える
-1

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);

もありView.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>

次に、次のようにします:

LinearLayout mytransparentLayout = (LinearLayout) findViewById(R.id.transparentLayout);
mytransparentLayout.setAlpha(0.5f);
于 2012-11-27T16:29:24.970 に答える