很多时候我们需要在程序内部为自定义控件添加圆角和阴影。这里我使用了Xamarin.Andoird实现:
1. 使用 ShapeDrawable 设置圆角
2. 使用 SetShadowLayer 设置阴影,但是我们要注意使用的 andoird sdk 版本。关于这个问题,可以阅览: http://stackoverflow.com/questions/17410195/setshadowlayer-android-api-differences
3. 使用 LayerDrawable 设置显示部分以显示阴影效果.
1. 使用 ShapeDrawable 设置圆角
ShapeDrawable backgroudDrawable = new ShapeDrawable(new RoundRectShape(new float[] { 8, 8, 8, 8, 8, 8, 8, 8 }, null, null));
2. 使用 SetShadowLayer 设置阴影,但是我们要注意使用的 andoird sdk 版本。关于这个问题,可以阅览: http://stackoverflow.com/questions/17410195/setshadowlayer-android-api-differences
backgroudDrawable.Paint.AntiAlias = true;
backgroudDrawable.Paint.SetStyle(Paint.Style.Fill);
backgroudDrawable.Paint.Color = Color.White;
backgroudDrawable.Paint.SetShadowLayer(7, 0, 0, Color.Black);
SetLayerType(Android.Views.LayerType.Software, null);
3. 使用 LayerDrawable 设置显示部分以显示阴影效果.