2016-06-14 3 views
2

私はlayout.xml次ている:私はこのような親LinearLayoutの背景色を設定 AndroidのImageViewの - ImageViewのは着色しない方法

<LinearLayout 
     android:id="@+id/layout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <ImageView 
      android:id="@+id/image" 
      android:layout_width="100dp" 
      android:layout_height="50dp" 
      android:src="@drawable/logo"/> 
     ... 
    </LinearLayout> 

:しかし

LinearLayout layout = (LinearLayout) view.findViewById(R.id.layout); 
    layout.setBackgroundColor(Color.parseColor("#727272")); 
    layout.setAlpha(0.5f); 

を、ImageView(ID :画像)が着色される。その親レイアウトの背景色を設定している間にImageViewを色づけしない方法はありますか?

+0

eventLogoLayoutとは何ですか? –

+0

なぜeventLogoLayout.setAlpha(0.5f)を設定しますか?それはおそらくあなたのロゴに依存する色合いです。スクリーンショットをここに添付する必要があります。 – ikhsan

+0

ImageView background = nullを設定します。それはあなたを助けるかもしれない – Konstantin

答えて

0

なお、画像は私が親のレイアウトのためのsetAlphaを呼び出すので、着色されていることが判明:私は親のレイアウトのため、50%の不透明度を設定するため

layout.setAlpha(0.5f); 

しかし、それが必要になります。だから私は、親のレイアウトの背景色のアルファとRGBを設定するために、以下の方法を使用し、それは動作します:親のレイアウトの背景色は、子供の画像を着色せずに設定されます。

LinearLayout layout = (LinearLayout) view.findViewById(R.id.layout); 
layout.setBackgroundColor(BitmapDrawableUtility. getColorByOpacityPercentage(calculateOpacity(Color.parseColor("#727272"), 50)); 


public static int getColorByOpacityPercentage(int color, double percentage) { 
    int transparency = (int) Math.round((percentage/100.0) * 255.0); 
    return Color.argb(transparency, Color.red(color), Color.green(color), Color.blue(color)); 
}