如何创建Android的自定义视图 [英] How to create a custom view in android

查看:116
本文介绍了如何创建Android的自定义视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要学习,如何创建自定义视图即可。我已经通过多个教程走了,并没有得到我想要的(我的意思是概念)。

I want to learn, how to create custom view. I have gone through multiple tutorial and didn't get what i want(I mean concept).

我学到

我分享我的概念,如果我错了,请大家指正。

I am sharing my concept,if i am wrong please correct me.

如果你想在标准视图中的微小的变化则继承本身(例如扩展搜索栏),并对其进行自定义。

If you want to make a minor change to the standard view then inherit itself(e.g extends seekbar) and customize it.

但是,如果你想使困难或多功能观点,我们要继承查看班级

But if you want to make difficult or multifunction view, We should inherit View Class

当我们继承一个视图。

有两种方法neccessary


  1. 的onDraw(帆布油画)//它每次调用它,也可以通过拨打无效。

  2. onMeasure //它衡量的实际宽度和大小,并相应设置我们viewit

无论你想在视图中绘制可以用帆布做。(我说得对不对)

Whatever you want to draw on View can be done using canvas;(Am i right).

要定义附加属性创建您的res的attrs.xml文件/文件夹值。并添加<申报-设置样式名称=YourCustomView方式> ,并添加属性,它

To define additional attributes create an attrs.xml file in your res/values folder. and add <declare-styleable name="YourCustomView"> and add attributes to it.

使用TypedArray通话recyle方法得到的视图的构造这些属性。

get these attribute in the constructor of the View using TypedArray call recyle method.

我的困惑


  1. 我们可以借鉴的东西,而不使用Canvas

  2. 可我们得出的ImageView无需将其转换为位图。

  3. 我只是想创建一个可以像旋转的自定义的ImageView
    一个dial​​View但应旋转一半(半圆),也希望
    绘制它的外面的进展。使用canvas.drawArc()

我想实现

我想创建自己的自定义按钮,我已搜查谷歌了,但没有找到我想要看到我的问题在这里。

I want to create my own custom knob, I have searched our google but didn't find what i want see my questions here

<一个href=\"http://stackoverflow.com/questions/27717535/rotatory-knob-moving-between-150-and-210-degree\">First问

<一个href=\"http://stackoverflow.com/questions/27707447/i-simply-want-to-draw-two-image-one-in-a-single-view\">Second问

由于提前....

推荐答案

1)您可以使用OpenGL。否则,你需要的画布。画布定义了你绘图,没有它(或等值的openGL),我们不知道在哪里画。你可能不希望直接绘制到屏幕上,其共同绘制在许多情况下,位图。

1)You can use openGL. Otherwise you need a canvas. The canvas defines where you're drawing to, without it (or the openGL equivalent) we don't know where to draw. You might not want to draw directly to the screen, its common to draw to bitmaps in many cases.

2)你的问题并没有做出很大的意义。你为什么要画一个ImageView的,其他的不是让它绘制自己?

2)Your question doesn't make a lot of sense. Why would you want to draw an ImageView, other than by letting it draw itself?

3)要做到这一点最简单的方法是使用一个正常的图像查看和调用setRotation旋转根据需要对其进行。

3)Easiest way to do that is to use a normal image view and call setRotation to rotate it as needed.

这篇关于如何创建Android的自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆