首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Xamarin android中实现线性渐变?

如何在Xamarin android中实现线性渐变?
EN

Stack Overflow用户
提问于 2018-09-03 21:26:37
回答 1查看 704关注 0票数 0

我想实现一些像我在我的应用程序dynamically.But中附加的图像,我不知道如何在C# Gradient enter image description here中指定中心颜色,起始颜色,结束颜色和角度

如何在Xamarin android原生平台中以编程方式实现这一点

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-04 07:34:04

GradientActivity.cs

代码语言:javascript
复制
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

代码语言:javascript
复制
<?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>

输出

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52150715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档