2017-04-06 209 views
0

我想設置ImageView透明邊緣。 我知道如何將整個ImageView設置爲透明,就像我在下面的代碼中所做的一樣。但是,有沒有什麼辦法可以設置只有圖像的邊緣/邊框是透明的?例如。我希望ImageView的70%(內部)是正常的,而剩餘的30%(外部)應該是透明的。 我的目標是重疊兩個圖像(雲和鳥),以便我可以看到鳥在雲周圍「飛」,同時保持雲的原始顏色。ImageView透明設置邊緣/邊框Android

public class FirstActivity extends AppCompatActivity 
{ 
    ImageView clouds; 
    ImageView birds; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.first_layout); 

     clouds = (ImageView)findViewById(R.id.cloudView); 
     birds = (ImageView)findViewBy(R.id.birdView); 

     clouds.setImageResource(R.drawable.cloudsImage); 
     birds.setImageResource(R.drawable.birdsImage); 

     clouds.setAlpha(0.5f); 
    } 
} 

非常感謝這方面的任何幫助!

+0

你可以改變alpha值 –

回答

0

我的目標是重疊的兩個圖像(雲和鳥),這樣我可以看到鳥「飛」雲霧繚繞而維修器材雲原來的顏色

如果你的背景是不必須是ImageView你可以這樣做:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/clouds"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/flying_bird"/> 

</RelativeLayout>