2016-10-25 11 views
1

私はImageViewを持っています。私はそれの上に透明なオーバーレイを追加するが、私はそれを行う方法がわからない。たとえば、これは私のイメージである:ImageViewにイメージオーバーレイをカスタムカラーで追加する

enter image description hereそれは次のようになりますので、私はそれに私のオーバーレイを追加したい

enter image description here

あなたはその上に黒のオーバーレイがある見ることができるように、ポイント私はこのオーバーレイをカスタマイズ可能にし、色を変えなければならないということです。良い結果を見つけるためにどのキーワードを検索すべきかわかりません。

+1

をしたいとまったく同じ方法を取得する勾配で少しプレイしているよ、これはあなたが何を意味するかだと思う...しかし、 2つの画像ビューでFrameLayoutを使用する場合2番目の画像は最初の画像の上に表示されます –

+0

@RoeeN回答ありがとうございます。実際には2つのimageViewを持つことができますが、どのようにAndroidのさまざまな色のオーバーレイを作成しますか? –

+0

あなたはそれに背景色を付けることができます。色の影響を与えるアルファレベルを設定します。 –

答えて

1

shader.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
     android:startColor="#00000000" 
     android:centerColor="#7d000000" 
     android:endColor="#7d000000" 
     android:dither="true" 
     /> 
</shape> 


<ImageView 

    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/bla2" /> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/shader"/> 

私はあなたがそれをあなたが私はあなたが何を意味するかわからないんだけど

+0

ありがとうございます。これはまさに私が必要とするものです。シェーダの色をプログラム的に変更できますか? –

+0

は試したことがありません...おそらくプログラムで作成し、更新することができます これをチェックしてくださいhttp://stackoverflow.com/questions/6115715/how-do-i-programmatically-set-the-background-color-gradient-on -a-custom-title-ba –

+0

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

2
<?xml version="1.0" encoding="utf-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item> 
      <bitmap android:src="@drawable/android_red" 
      android:gravity="center" /> 
     </item> 
     <item android:top="10dp" android:left="10dp"> 
      <bitmap android:src="@drawable/android_green" 
      android:gravity="center" /> 
     </item> 
     <item android:top="20dp" android:left="20dp"> 
      <bitmap android:src="@drawable/android_blue" 
      android:gravity="center" /> 
     </item> 

enter image description here

またはプログラム

public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) { 
      Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), 

    bmp1.getHeight(), bmp1.getConfig()); 
       Canvas canvas = new Canvas(bmOverlay); 
       canvas.drawBitmap(bmp1, new Matrix(), null); 
       canvas.drawBitmap(bmp2, 0, 0, null); 
       return bmOverlay; 
      } 

または使用でframeLayout

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="20dp" 
    android:background="#000000"> 
    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:padding="20dp" 
     android:background="@android:color/holo_red_dark"> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:padding="20dp" 
      android:orientation="vertical" 
      android:background="@android:color/holo_purple"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       ... 
       "> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       ... 
       /> 
     </LinearLayout> 

    </LinearLayout> 
    </FrameLayout> 
</LinearLayout> 

enter image description here

+0

本当にありがとう、しかし実際には私はGlideを使用していますので、私は2つのseprate imageViewsを使用しなければならないようです...問題は異なる色でオーバーレイレイヤーを作成する方法ですか? –

関連する問題