【问题标题】:Not able to understand ColorDrawable in Android无法理解 Android 中的 ColorDrawable
【发布时间】:2011-07-26 16:15:25
【问题描述】:

我已经学习 Android 几天了(或至少尝试过),但我可以绕过 Drawables、ColorDrawables 等。我尝试使用一个简单的 ColorDrawable,用红色填充整个屏幕......

<color xmlns:android="http://schemas.android.com/apk/res/android">
android:color="#FFFF0000"
</color>

但我无法理解 Canvas、Paint 和 ColorDrawables 对象。我在书籍、谷歌、Android Docs 和 StackOverflow 中进行了搜索,但我无法直接回答应该如何调用事物以便在屏幕可绘制对象(ColorDrawables、ShapeDrawables、图像......等)上显示。

我知道我的问题可能过于笼统,但有人可以帮助我,或者至少为我指出一本关于这些东西的更详细和更深入的信息的书或网页吗?

提前致谢。

【问题讨论】:

    标签: android colors drawable


    【解决方案1】:

    特别是对于纯色,您通常不会在代码中使用 ColorDrawable,因为大多数标准类都会为您提供 setBackgroundColor(int);在 XML 中,android:background attribute 允许您指定颜色。

    假设您有更复杂的想法。通常,您将在 XML 布局中比在代码中更多地使用 Drawables。在代码中,您可以选择让Drawable 自己绘制或继承View 并覆盖View.onDraw(Canvas) 并绘制您想要的内容。例如,您可以编写一个新的ColorDrawable,然后通过ColorDrawable.draw(Canvas) 让它自己绘制,但您也可以通过Canvas.drawColor(int) 做同样的事情。

    【讨论】:

      【解决方案2】:

      看看有没有帮助

      Drawable Manual

      【讨论】:

      • 很遗憾,没有,我已经找到了,但它只是描述了 xml 文件,但我所说的更多是关于 Android 如何绘制东西的解释,但谢谢。
      猜你喜欢
      • 2012-05-01
      • 2016-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 2014-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多