Gradinet不适用于kitkat设备android

Gradinet不适用于kitkat设备android,android,android-layout,gradient,android-6.0-marshmallow,android-4.4-kitkat,Android,Android Layout,Gradient,Android 6.0 Marshmallow,Android 4.4 Kitkat,我已经对activity_main.xml应用了梯度,当我在棉花糖设备上运行时,应用了梯度,但当我在kitkat设备上运行时,不应用梯度。下面是活动_main.xml的外观 棉花糖用户界面屏幕: Kitkat用户界面屏幕: 下面是activity_main.xml源代码 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/an

我已经对activity_main.xml应用了梯度,当我在棉花糖设备上运行时,应用了梯度,但当我在kitkat设备上运行时,不应用梯度。下面是活动_main.xml的外观

棉花糖用户界面屏幕:

Kitkat用户界面屏幕:

下面是activity_main.xml源代码

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

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

</ScrollView>

这是我正在使用的梯度代码

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:angle="90"
    android:centerColor="#295e7c"
    android:centerY="0"
    android:endColor="#303a70"
    android:gradientRadius="775dp"
    android:startColor="#56a68d"
    android:type="radial" />
<corners android:radius="0dp" />
</shape>

尝试从
gradientRadius

<gradient
    android:angle="90"
    android:centerColor="#295e7c"
    android:centerY="0"
    android:endColor="#303a70"
    android:gradientRadius="775"
    android:startColor="#56a68d"
    android:type="radial" />

我已经实现了您所说的代码,它对kitkat和棉花糖版本都很有效。有一个问题,如果您使用多个布局,那么您可以在这些类中调用此方法

ssv = (ScrollView) findViewById(R.id.ssv);

    if (Build.VERSION.SDK_INT <= 22) {
    GradientDrawable gradientDrawable = new GradientDrawable(
    GradientDrawable.Orientation.TOP_BOTTOM,
    new int[]{0xFF56a68d, 0xFF295e7c, 0xFF303a70});
    gradientDrawable.setCornerRadius(0f);
    gradientDrawable.setGradientRadius(775f);
    gradientDrawable.setGradientCenter(0.5f, 0);
    gradientDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
    ssv.setBackgroundDrawable(gradientDrawable);
    }
ssv=(滚动视图)findviewbyd(R.id.ssv);

如果(Build.VERSION.SDK_INT@Karthik)不删除gradientRadius。仅将值从775dp更改为仅775。仅删除dp。是的,我已更改了代码,正如您所说,我在kitkat设备中工作良好,但在Marshalllow设备中它并不好看。775的值需要根据您的要求进行调整。