2

透明な黒色を画像の上に追加して暗くしたいと思います。ImageViewを暗い透明にする

enter image description here

  <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:id="@+id/rest_image" 
        android:layout_width="match_parent" 
        android:layout_height="150dp" 
        android:adjustViewBounds="true" 
        android:scaleType="centerCrop" 
        /> 
      </RelativeLayout> 

Iは、αパラメータを設定することができるが、色の変化は、白です。 このように暗いイメージを作りたいです。 どうすればxmlまたはJavaコードで実行できますか。私は条件に基づいてそれを設定します。

ありがとうございました。

+0

暗い「シェイプ」を作成し、「FrameLayout」で背景として使用できます。 –

+1

または、あなたは 'android colormatrix darken'のためにgoogleすることができます –

答えて

6

あなたが必要とするものは色合いと呼ばれます。あなたのImageViewに色合いを適用します。

<ImageView 
    ... 
    android:tint="#6F000000" 
    /> 
0

最も簡単/最速ソリューションは

があなたのImageViewの上に第二の層を追加します(表示することができ、ImageViewのである必要はありません)XMLになります所望の色/アルファを有する。必要に応じて表示/非表示にします。

  <ImageView 
       android:id="@+id/rest_image" 
       android:layout_width="match_parent" 
       android:layout_height="150dp" 
       android:adjustViewBounds="true" 
       android:scaleType="centerCrop" 
       /> 

      <View 
       android:id="@+id/overlay_image" 
       android:layout_width="match_parent" 
       android:layout_height="150dp" 
       android:background=“@color/yourColorWithAlpha" 
       /> 
     </RelativeLayout> 
+0

ありがとう、これは働いた –

0

この第二のImageViewのは、透明色を設定します試してみてください。必要に応じて高さを調整します。

500000 - 最後の4桁は黒色を表し、最初の2桁は設定したいアルファを表します。

     <RelativeLayout 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 

         <ImageView 
          android:id="@+id/rest_image" 
          android:layout_width="match_parent" 
          android:layout_height="150dp" 
          android:adjustViewBounds="true" 
          android:scaleType="centerCrop" 
          /> 

          <ImageView 
          android:layout_width="match_parent" 
          android:layout_height="150dp" 
          android:background="#500000" 
          /> 
        </RelativeLayout> 
関連する問題