


下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android開(kāi)發(fā)中如何理解RadioButton及路徑繪制
這篇文章將為大家詳細(xì)講解有關(guān)Android開(kāi)發(fā)中如何理解RadioButton及路徑繪制,文章內(nèi)容質(zhì)量較高,因此在下分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。這個(gè)例子是繪制多邊形,多義形和路徑,采用單選鈕RadioButton來(lái)選擇Polys和Path示例:UI設(shè)計(jì)為上部分用來(lái)顯示繪圖內(nèi)容,下部分為兩個(gè)單選按鈕Polys,Path。這樣layout就和main.xml
不一樣,main.xml只含一個(gè)com.pstreets.graphics2d.GuidebeeGraphics2DView。因此需在res\layout下新建一個(gè)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=”P(pán)olys”
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=”P(pán)ath”
android:id=”@+id/radioPath”
android:layout_width=”wrap_content”
android:textColor=”@color/black”
android:layout_height=”wrap_content”>
</RadioButton>
</RadioGroup>
</LinearLayout>
</LinearLayout>RadioButton需包含在RadioGroup中做為一個(gè)分組,這里將Polys設(shè)為選中。定義好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);
}應(yīng)為需要處理按鍵消息,所以定義了兩個(gè)RadioButton對(duì)象,可以通過(guò)findViewById獲取實(shí)例。因?yàn)閮蓚€(gè)RadioButton這里采用同樣的處理方法,可以讓Path實(shí)現(xiàn)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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 個(gè)人辦公用品采購(gòu)合同規(guī)范
- 數(shù)字化圖書(shū)館建設(shè)協(xié)議
- 馬匹買(mǎi)賣(mài)合同
- 豬場(chǎng)生產(chǎn)技術(shù)服務(wù)協(xié)議
- 產(chǎn)品召回與處理協(xié)議
- 雕塑制作合同協(xié)議書(shū)
- 企業(yè)級(jí)云計(jì)算解決方案服務(wù)合同
- 戶外運(yùn)動(dòng)場(chǎng)地租賃使用協(xié)議
- 文藝晚會(huì)演出合同
- 戰(zhàn)略規(guī)劃咨詢合同
- 中國(guó)教育史課件
- 幼兒園小班美術(shù)欣賞《漂亮的糖紙》課件
- 互聯(lián)網(wǎng)接入服務(wù)提供商服務(wù)承諾
- 2024年全國(guó)中學(xué)生生物學(xué)聯(lián)賽試題含答案
- 城市綠化景觀設(shè)施安裝與維護(hù)合同
- 解除凍結(jié)及撤銷納入失信和限高令申請(qǐng)書(shū)(文本)
- 2024年河北省公務(wù)員錄用考試《行測(cè)》真題及答案解析
- 英語(yǔ)語(yǔ)法-形容詞和副詞-復(fù)習(xí)資料
- 數(shù)字校園網(wǎng)絡(luò)設(shè)施調(diào)查 課件 2024-2025學(xué)年冀教版(2024)初中信息科技七年級(jí)上冊(cè)
- 美食街道策劃方案
- 河北醫(yī)科大學(xué)第二醫(yī)院招聘工作人員真題
評(píng)論
0/150
提交評(píng)論