質問編集履歴
2
コード掲載
test
CHANGED
File without changes
|
test
CHANGED
@@ -47,3 +47,71 @@
|
|
47
47
|
要はxmlでmatch_parentするとどの画面でもフィットしてくれるじゃないですか。
|
48
48
|
|
49
49
|
それをプログラムで実現したいです。
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
float dp;
|
56
|
+
|
57
|
+
public Graphics(SerfaceHolder holder, Activity activty){
|
58
|
+
|
59
|
+
dp = activity.getResources().getDisplayMetrics().density;
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
//ビットマップの描画
|
64
|
+
|
65
|
+
public void drawBitmap(Bitmap bitmap, float x, float y, int revers) {
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
Matrix matrix = new Matrix();
|
70
|
+
|
71
|
+
if (canvas == null) return;
|
72
|
+
|
73
|
+
while (bitmap != null) {
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
float w = bitmap.getWidth();
|
78
|
+
|
79
|
+
float h = bitmap.getHeight();
|
80
|
+
|
81
|
+
float sx = x;
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
if (revers == 1) {
|
88
|
+
|
89
|
+
sx = x;
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
if (revers == -1) {
|
94
|
+
|
95
|
+
sx = x + w;
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
matrix.setScale(revers * (dp), 1 * (dp));
|
100
|
+
|
101
|
+
matrix.postTranslate( sx * (dp), y * (dp));
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
canvas.drawBitmap(bitmap, matrix, paint);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
break;
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
```
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -41,3 +41,9 @@
|
|
41
41
|
このようにしたい
|
42
42
|
|
43
43
|
![イメージ説明](51abc5daee595a1ac91564ac60cf9f29.png)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
要はxmlでmatch_parentするとどの画面でもフィットしてくれるじゃないですか。
|
48
|
+
|
49
|
+
それをプログラムで実現したいです。
|