- Buat Projek Baru.
- Isikan Kriteria dan desain sesuai yang anda inginkan.
- Ketikan Coding dibawah ini pada layout mainActivity.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
- Pilih gambar dan masukan pada folder xxhdpi.
- Isikan coding berikut pada Activity Main pada src.
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new canvas7(this));
}
static public class canvas7 extends View{
Bitmap gambarkudangambarmu;
public canvas7(Context context){
super(context);
gambarkudangambarmu = BitmapFactory.decodeResource(context.getResources(),R.drawable.aaa);
}
@SuppressLint("DrawAllocation")
protected void onDraw(Canvas canvas){
Paint paint=new Paint();
canvas.drawBitmap(gambarkudangambarmu, 100, 200,paint);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
- Pada coding R.drawable.aaa,”aaa”
diganti dengan nama gambar yang anda masukan tadi pada folder
xx-hdpi.
- Output :
0 komentar:
Post a Comment
Note: only a member of this blog may post a comment.