2016-06-07 102 views
3

我試圖在我的應用程序上設置徑向線性背景。我目前正在預覽,但是當我在我的三星Galaxy S4上運行我的應用程序時,它使整個背景只是起始顏色。android studio - 徑向漸變不適用於手機

預覽一下:

enter image description here

三星Galaxy S4的外觀:

enter image description here

這裏是我的XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 
    <gradient 
     android:type="radial" 
     android:startColor="#f3e5f5" 
     android:endColor="#9c27b0" 
     android:gradientRadius="600" 
     android:angle="270" 
     android:centerX="50%" 
     android:centerY="20%"/> 

</shape> 

任何想法有什麼不對?

回答

0

我發現了另一個解決方法是 - 設置漸變背景代碼:

findViewById(R.id.bg).setBackground(ContextCompat.getDrawable(context,R.drawable.bg_gradient));