2016-06-14 21 views
2

我有以下layout.xml的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像這樣的背景顏色:

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:

layout.setAlpha(0.5f); 

但是,我設置父佈局的50%的不透明度是必需的。所以我使用下面的方式爲父級佈局的背景顏色設置Alpha和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)); 
}