編輯:關於Android編程
先看需求,要求這種效果
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+yc+0+sLrPC9wPgo8cD48P3htbCB2ZXJzaW9uPQ=="1.0" encoding="utf-8"?>
android:color="@android:color/white" />
android:width="55dp" />
android:left="15dp"
android:right="15dp"
android:top="15dp" />
android:color="@android:color/white" />
android:width="40dp" />
android:left="15dp"
android:right="15dp"
android:top="15dp" />
android:scaleWidth="50%"
android:scaleHeight="50%"
/>
再來重頭從學習drawable^_^
Android把可繪制的對象抽象為Drawable,不同的圖形圖像資源就代表著不同的drawable類型。Android FrameWork提供了一些具體的Drawable實現,通常在代碼中都不會直接接觸Drawable的實現類。
Shape
作用:XML中定義的幾何形狀
位置:res/drawable/文件的名稱.xml
使用的方法:
Java代碼中:R.drawable.文件的名稱
XML中:Android:background="@drawable/文件的名稱"
屬性:
一、ColorDrawable
Android:shape=["rectangle" | "oval" | "line" | "ring"] 其中rectagle矩形,oval橢圓,line水平直線,ring環形
中子節點的常用屬性:
漸變 Android:startColor 起始顏色
Android:endColor 結束顏色
Android:angle 漸變角度,0從上到下,90表示從左到右,數值為45的整數倍默認為0;
Android:type 漸變的樣式 liner線性漸變 radial環形漸變 sweep
填充 Android:color 填充的顏色
描邊 Android:width 描邊的寬度
Android:color 描邊的顏色
Android:dashWidth 表示'-'橫線的寬度
Android:dashGap 表示'-'橫線之間的距離
圓角 Android:radius 圓角的半徑 值越大角越圓
Android:topRightRadius 右上圓角半徑
Android:bottomLeftRadius 右下圓角角半徑
Android:topLeftRadius 左上圓角半徑
Android:bottomRightRadius 左下圓角半徑
填充 android:bottom="1.0dip" 底部填充
android:left="1.0dip" 左邊填充
android:right="1.0dip" 右邊填充
android:top="0.0dip" 上面填充
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
color
xmlns:android
=
"http://schemas.android.com/apk/res/android"
3
android:color
=
"#FF0000"
/>
當然也可以使用Java代碼創建ColorDrawable,需要注意的是Android中使用一個int類型的數據表示顏色值,通常習慣使用十六進制格式的數據表示顏色值。一個int類型包含四個字節,分別代表顏色的4個組成部分:透明度(Alpha)、紅(RED)、綠(GREEN)、藍(BLUE),每個部分由一個字節(8個bit)表示,取值范圍為0~255。在xml中使用顏色時可以省略透明度(Alpha)部分,如#ff0000表示紅色。但是在代碼中必須要明確指出透明度(Alpha)代表的數據,如果省略了就表示完全透明的顏色,例如0xFFFF0000表示紅色,而0xFF0000雖然也表示紅色,但它卻是完全透明的,也就是說當繪制到畫布上時,看不出有任何效果。
1
ColorDrawable drawable =
new
ColorDrawable(
0xffff0000
);
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
shape
xmlns:android
=
"http://schemas.android.com/apk/res/android"
>
3
<
size
/> //定義區域的大小
4
<
gradient
>//設置區域背景的漸變效果
5
<
solid
/>//設置區域的背景顏色,如果設置了solid會覆蓋gradient的效果
6
<
stroke
/>//設置區域的邊框效果
7
<
padding
/>//設置區域的內邊距
8
shape
>
01
02
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
03
<
shape
04
xmlns:android
=
"http://schemas.android.com/apk/res/android"
05
android:shape
=
"oval"
>
06
07
<
gradient
08
android:startColor
=
"#ff0000"
09
android:centerColor
=
"#00ff00"
10
android:endColor
=
"#0000ff"
11
android:angle
=
"90"
/>
12
<
stroke
13
android:width
=
"3dip"
14
android:color
=
"#fff"
15
android:dashWidth
=
"4dip"
16
android:dashGap
=
"5dip"
/>
17
shape
>
18
19
20
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
21
<
shape
xmlns:android
=
"http://schemas.android.com/apk/res/android"
22
android:shape
=
"ring"
android:innerRadiusRatio
=
"8"
23
android:thicknessRatio
=
"3"
android:useLevel
=
"false"
>
24
<
gradient
android:type
=
"sweep"
android:useLevel
=
"false"
25
android:startColor
=
"#ff0000"
android:endColor
=
"#0000ff"
android:centerColor
=
"#00ff00"
/>
26
shape
>
27
28
29
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
30
<
shape
xmlns:android
=
"http://schemas.android.com/apk/res/android"
31
android:shape
=
"ring"
android:innerRadius
=
"0dip"
32
android:thickness
=
"70dip"
android:useLevel
=
"false"
>
33
<
gradient
android:type
=
"radial"
android:useLevel
=
"false"
android:gradientRadius
=
"70"
34
android:startColor
=
"#ff0000"
android:endColor
=
"#0000ff"
android:centerColor
=
"#00ff00"
/>
35
shape
>
圖6-1 線性漸變效果的橢圓
圖6-2 平鋪漸變效果的圓環
圖6-3 發散漸變效果的圓
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
bitmap
xmlns:android
=
"http://schemas.android.com/apk/res/android"
3
android:src
=
"@drawable/png_icon_416"
4
android:tileMode
=
"mirror"
5
android:antialias
=
"true"
6
android:dither
=
"true"
7
>
8
bitmap
>
1
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.png_icon_416);
2
BitmapDrawable mBitmapDrawable =
new
BitmapDrawable(mBitmap);
3
mBitmapDrawable.setTileModeXY(TileMode.MIRROR, TileMode.MIRROR);
4
mBitmapDrawable.setAntiAlias(
true
);
5
mBitmapDrawable.setDither(
true
);
6
mDrawable = mBitmapDrawable;
圖6-4 BitmapDrawable運行效果圖
圖6-5 點九圖片示意圖
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
nine-patch
3
xmlns:android
=
"http://schemas.android.com/apk/res/android"
4
android:src
=
"@drawable/droid_logo"
5
android:dither
=
"true"
/>
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
bitamp
3
xmlns:android
=
"http://schemas.android.com/apk/res/android"
4
android:src
=
"@drawable/droid_logo"
5
android:dither
=
"true"
/>
圖6-6 原始點九圖片
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
inset
xmlns:android
=
"http://schemas.android.com/apk/res/android"
3
android:drawable
=
"@drawable/bitmap_bell"
4
android:insetLeft
=
"20dp"
5
android:insetRight
=
"20dp"
6
android:insetTop
=
"20dp"
7
android:insetBottom
=
"20dp"
8
>
9
inset
>
圖6-8 InsetDrawable運行效果圖
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
clip
xmlns:android
=
"http://schemas.android.com/apk/res/android"
3
android:clipOrientation
=
"horizontal"
4
android:drawable
=
"@drawable/bitmap_android"
5
android:gravity
=
"left"
6
>
7
clip
>
01
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
02
<
clip
xmlns:android
=
"http://schemas.android.com/apk/res/android"
03
android:clipOrientation
=
"horizontal"
04
android:gravity
=
"left"
05
>
06
<
bitmap
07
android:src
=
"@drawable/android_text"
08
android:gravity
=
"center"
09
/>
10
clip
>
七、ScaleDrawable
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
3
<
scale
xmlns:android
=
"http://schemas.android.com/apk/res/android"
4
android:drawable
=
"@drawable/smiley_smile"
5
android:scaleWidth
=
"100%"
6
android:scaleHeight
=
"100%"
7
>
8
9
scale
>
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
rotate
xmlns:android
=
"http://schemas.android.com/apk/res/android"
3
android:drawable
=
"@drawable/smiley_smile"
4
android:pivotX
=
"50%"
5
android:pivotY
=
"50%"
6
>
7
8
9
rotate
>
01
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
02
<
animation-list
xmlns:android
=
"http://schemas.android.com/apk/res/android"
03
android:oneshot
=
"false"
>
04
<
item
05
android:drawable
=
"@drawable/level1"
06
android:duration
=
"300"
07
/>
08
<
item
09
android:drawable
=
"@drawable/level2"
10
android:duration
=
"300"
11
/>
12
<
item
13
android:drawable
=
"@drawable/level3"
14
android:duration
=
"300"
15
/>
16
<
item
17
android:drawable
=
"@drawable/level4"
18
android:duration
=
"300"
19
/>
20
<
item
21
android:drawable
=
"@drawable/level5"
22
android:duration
=
"300"
23
/>
24
animation-list
>
1
mHandler.postDelayed(
new
Runnable() {
2
3
@Override
4
public
void
run() {
5
// TODO Auto-generated method stub
6
((AnimationDrawable)mDrawable).start();
7
8
}
9
},
1000
);
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
layer-list
xmlns:android
=
"http://schemas.android.com/apk/res/android"
>
3
<
item
android:drawable
=
"@drawable/layer1"
/>
4
<
item
android:drawable
=
"@drawable/layer2"
/>
5
<
item
android:drawable
=
"@drawable/layer3"
/>
6
layer-list
>
01
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
02
<
level-list
xmlns:android
=
"http://schemas.android.com/apk/res/android"
>
03
04
<
item
05
android:maxLevel
=
"2000"
06
android:drawable
=
"@drawable/level1"
/>
07
<
item
08
android:maxLevel
=
"4000"
09
android:drawable
=
"@drawable/level2"
/>
10
<
item
11
android:maxLevel
=
"6000"
12
android:drawable
=
"@drawable/level3"
/>
13
<
item
14
android:maxLevel
=
"8000"
15
android:drawable
=
"@drawable/level4"
/>
16
<
item
17
android:maxLevel
=
"10000"
18
android:drawable
=
"@drawable/level5"
/>
19
20
level-list
>
01
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
02
<
selector
xmlns:android
=
"http://schemas.android.com/apk/res/android"
>
03
<
item
android:state_focused
=
"false"
04
android:state_pressed
=
"false"
05
android:drawable
=
"@drawable/gradient_normal"
06
/>
07
08
<
item
android:state_pressed
=
"true"
09
android:drawable
=
"@drawable/gradient_pressed"
10
/>
11
12
<
item
android:state_focused
=
"true"
13
android:drawable
=
"@drawable/gradient_focused"
14
/>
15
16
selector
>
1
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
transition
xmlns:android
=
"http://schemas.android.com/apk/res/android"
>
3
<
item
android:drawable
=
"@drawable/smiley_smile"
/>
4
<
item
android:drawable
=
"@drawable/smiley_smile_glasses"
/>
5
6
transition
>
1
mHandler.postDelayed(
new
Runnable() {
2
3
@Override
4
public
void
run() {
5
// TODO Auto-generated method stub
6
((TransitionDrawable)mDrawable).startTransition(
2000
);
7
}
8
},
1000
);
今天在寫微信登錄,花了半天時間搞定、然後寫下自己的筆記,希望幫助更多的人。歡迎各位指教。微信授權登錄,官方說的不是很清楚、所以導致有一部分的坑。微信注冊應用平台的應用簽名
Android安全加密專題文章索引 Android安全加密:對稱加密 Android安全加密:非對稱加密 Android安全加密:消
首先引申下AIDL,什麼是AIDL呢?IPC? ------ Designing a Remote Interface Using AIDL 通常情況下,我們在同一進程內
獲取域ID和方法ID均分別需要域描述符合方法描述符,域描述符合方法描述符都可以通過下表中的Java類型簽名映射獲得。