Created
August 26, 2011 23:46
-
-
Save osima/1174714 to your computer and use it in GitHub Desktop.
custom view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
> | |
<jp.osima.android.mindmemo.MCanvas | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
/> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.osima.android.mindmemo; | |
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.Paint; | |
import android.graphics.Rect; | |
import android.util.AttributeSet; | |
import android.view.MotionEvent; | |
import android.view.View; | |
public class MCanvas extends View{ | |
public MCanvas(Context context,AttributeSet attrs){ | |
super(context,attrs); | |
} | |
public void onDraw(Canvas canvas){ | |
// 現在のViewのサイズを得る | |
int w = getWidth(); | |
int h = getHeight(); | |
Paint fill_paint = new Paint(); | |
fill_paint.setStyle(Paint.Style.FILL); | |
fill_paint.setColor(Color.WHITE); | |
Rect rect=new Rect(0,0,w,h); | |
canvas.drawRect(rect, fill_paint); | |
Paint draw_paint = new Paint(); | |
draw_paint.setStyle(Paint.Style.STROKE); | |
draw_paint.setColor(Color.BLACK); | |
int space=10; | |
Rect rect2=new Rect(0+space,0+space,w-space,h-space); | |
canvas.drawRect(rect2, draw_paint); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment