【问题标题】:how to fix Scale of android drawable in running如何在运行中修复 android drawable 的比例
【发布时间】:2016-02-18 18:12:42
【问题描述】:

问题是我的可绘制背景没有显示为 android Designer

我的项目包含这个

         <TextView
            android:id="@+id/BloodType"
            android:layout_width="40px"
            android:layout_height="40px"
            android:background="@drawable/circle"
            android:gravity="center"
            android:textIsSelectable="false"
            android:textColor="#ffffff" />

这是 circle.mxl

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
    android:endColor="#ffffff"
    android:gradientRadius="10"
    android:startColor="#ff0522"
    android:type="radial"></gradient>
<stroke
    android:width="1dp"
    android:color="#000000"></stroke>

谁能帮帮我 因为我是安卓开发新手

this image showing the difference between designer and real running and may show problem if you cant understand me

thanxx 提前...

【问题讨论】:

  • 我不明白你的代码中有android:innerRadius="1000dp"
  • 暂时忽略该行,仅用于测试,并不重要

标签: android drawable


【解决方案1】:

您有椭圆形可绘制对象,并使用具有相同高度和宽度的文本视图设置此可绘制对象。所以它的行为就像一个圆圈。

请看这里:How can I draw circle through XML Drawable - Android?

【讨论】:

  • 我不是指这种类型的差异,我是指笔触大小和渐变半径之间的差异
【解决方案2】:

我已经通过编程解决了我的问题,谢谢你

像这样

 GradientDrawable g = new GradientDrawable(
            GradientDrawable.Orientation.TL_BR, new int[]{Color.rgb(255, 10, 40), Color.WHITE});
    g.setStroke(1, Color.BLACK);
    g.setShape(g.OVAL);
    g.setGradientType(GradientDrawable.LINEAR_GRADIENT);
    g.setGradientRadius(X);
    View.setBackground(g);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 2020-10-14
    • 2012-03-27
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多