【移动应用开发技术】Android开发中如何理解RadioButton及路径绘制_第1页
【移动应用开发技术】Android开发中如何理解RadioButton及路径绘制_第2页
【移动应用开发技术】Android开发中如何理解RadioButton及路径绘制_第3页
免费预览已结束,剩余1页可下载查看

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

【移动应用开发技术】Android开发中如何理解RadioButton及路径绘制

这篇文章将为大家详细讲解有关Android开发中如何理解RadioButton及路径绘制,文章内容质量较高,因此在下分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。这个例子是绘制多边形,多义形和路径,采用单选钮RadioButton来选择Polys和Path示例:UI设计为上部分用来显示绘图内容,下部分为两个单选按钮Polys,Path。这样layout就和main.xml

不一样,main.xml只含一个com.pstreets.graphics2d.GuidebeeGraphics2DView。因此需在res\layout下新建一个polys.xml:<?xml

version=”1.0″

encoding=”utf-8″?>

<LinearLayout

xmlns:android=”/apk/res/android”

android:orientation=”vertical”

android:background=”@drawable/white”

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”>

<com.pstreets.graphics2d.GuidebeeGraphics2DView

android:id=”@+id/graphics2dview”

android:layout_weight=”1″

android:layout_width=”fill_parent”

android:layout_height=”wrap_content”/>

<LinearLayout

xmlns:android=”/apk/res/android”

android:layout_width=”wrap_content”

android:layout_height=”wrap_content”

android:orientation=”horizontal”

>

<RadioGroup

android:layout_width=”wrap_content”

android:orientation=”horizontal”

android:textSize=”20dp”

android:layout_height=”wrap_content”>

<RadioButton

android:text=”Polys”

android:id=”@+id/radioPolys”

android:layout_width=”wrap_content”

android:textColor=”@color/black”

android:checked=”true”

android:layout_height=”wrap_content”>

</RadioButton>

<RadioButton

android:text=”Path”

android:id=”@+id/radioPath”

android:layout_width=”wrap_content”

android:textColor=”@color/black”

android:layout_height=”wrap_content”>

</RadioButton>

</RadioGroup>

</LinearLayout>

</LinearLayout>RadioButton需包含在RadioGroup中做为一个分组,这里将Polys设为选中。定义好Layout资源后,修改Path.javaprivate

RadioButton

radioPoly;

private

RadioButton

radioPath;

public

void

onCreate(Bundle

savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.polys);

graphic2dView

=

(GuidebeeGraphics2DView)

findViewById(R.id.graphics2dview);

radioPath

=

(RadioButton)

findViewById(R.id.radioPath);

radioPoly

=

(RadioButton)

findViewById(R.id.radioPolys);

radioPath.setOnClickListener(this);

radioPoly.setOnClickListener(this);

}应为需要处理按键消息,所以定义了两个RadioButton对象,可以通过findViewById获取实例。因为两个RadioButton这里采用同样的处理方法,可以让Path实现OnClickListener,即:publicclassPathextends

Graphics2DActivity

implementsOnClickListener。完整代码如下:1

public

class

Path

extends

Graphics2DActivity

2

implements

OnClickListener

{

3

4

private

RadioButton

radioPoly;

5

private

RadioButton

radioPath;

6

7

public

void

onCreate(Bundle

savedInstanceState)

{

8

super.onCreate(savedInstanceState);

9

setContentView(R.layout.polys);

10

graphic2dView

11

=

(GuidebeeGraphics2DView)

12

findViewById(R.id.graphics2dview);

13

radioPath

=

(RadioButton)

findViewById(R.id.radioPath);

14

radioPoly

=

(RadioButton)

findViewById(R.id.radioPolys);

15

radioPath.setOnClickListener(this);

16

radioPoly.setOnClickListener(this);

17

}

18

19

@Override

20

protected

void

drawImage()

{

21

if

(radioPoly.isChecked())

{

22

drawPolys();

23

}

else

{

24

drawPaths();

25

}

26

graphic2dView.refreshCanvas();

27

28

}

29

30

@Override

31

public

void

onClick(View

view)

{

32

drawImage();

33

}

34

35

private

void

drawPaths()

{

36

AffineTransform

mat1;

37

38

//

The

path.

39

com.mapdigit.drawing.geometry.Path

path;

40

41

//

Colors

42

Color

redColor

=

new

Color(0x96ff0000,

true);

43

Color

greenColor

=

new

Color(0xff00ff00);

44

Color

blueColor

=

new

Color(0x750000ff,

true);

45

46

String

pathdata

47

=

"M

60

20

Q

-40

70

60

120

Q

160

70

60

20

z";

48

mat1

=

new

AffineTransform();

49

mat1.translate(30,

40);

50

mat1.rotate(-30

*

Math.PI

/

180.0);

51

path

=

com.mapdigit.drawing.geometry.Path.fromString(pathdata);

52

//

Clear

the

canvas

with

white

color.

53

graphics2D.clear(Color.WHITE);

54

55

graphics2D.setAffineTransform(new

AffineTransform());

56

SolidBrush

brush

=

new

SolidBrush(greenColor);

57

graphics2D.fill(brush,

path);

58

graphics2D.setAffineTransform(mat1);

59

60

brush

=

new

SolidBrush(blueColor);

61

com.mapdigit.drawing.Pen

pen

62

=

new

com.mapdigit.drawing.Pen(redColor,

5);

63

graphics2D.setPenAndBrush(pen,

brush);

64

graphics2D.draw(null,

path);

65

graphics2D.fill(null,

path);

66

67

}

68

69

private

void

drawPolys()

{

70

AffineTransform

mat1;

71

72

//

Colors

73

Color

redColor

=

new

Color(0x96ff0000,

true);

74

Color

greenColor

=

new

Color(0xff00ff00);

75

Color

blueColor

=

new

Color(0x750000ff,

true);

76

77

Polyline

polyline;

78

Polygon

polygon;

79

Polygon

polygon1;

80

81

String

pointsdata1

82

=

"59,45,95,63,108,105,82,139,39,140,11,107,19,65";

83

mat1

=

new

AffineTransform();

84

mat1.translate(30,

40);

85

mat1.rotate(-30

*

Math.PI

/

180.0);

86

polyline

=

new

Polyline();

87

polygon

=

new

Polygon();

88

polygon1

=

new

Polygon();

89

Point[]

points

=

Point.fromString(pointsdata1);

90

for

(int

i

=

0;

i

<

points.length;

i++)

{

91

polyline.addPoint(points[i].x,

points[i].y);

92

polygon.addPoint(points[i].x,

points[i].y);

93

polygon1.addPoint(points[i].x,

points[i].y);

94

}

95

//

Clear

the

canvas

with

white

color.

96

graphics2D.clear(Color.WHITE);

97

98

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论