我想在我的应用程序中动态实现类似我附加的图像。但我不知道如何在C#Gradient enter image description here中指定centercolor,startcolor,endcolor和angle
如何在Xamarin android原生平台中以编程方式实现此功能
GradientActivity.cs
protected override void OnCreate(Bundle savedInstanceState) {
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.GradientLayout);
ImageView ivTest = FindViewById<ImageView>(Resource.Id.ivSquare);
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TrBl, // "Top Right, Bottom Left"
new int[] { new Color(Color.Red), new Color(Color.White), new Color(Color.Blue) });
ivTest.Background = gd;
}
GradientLayout.axml
<?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" >
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@null"
android:id="@+id/ivSquare" />
</RelativeLayout>
产量