Draw path on custom View Android Example

Draw path on custom View Android Example - Hello friend inabnomaniiyaha, In the article that you read this time with the title Draw path on custom View Android Example, we have prepared this article well for you to read and take information in it. hopefully the contents of the post Artikel Android,what we write you can understand. Alright, happy reading.

Judul : Draw path on custom View Android Example
link : Draw path on custom View Android Example

Baca juga


Draw path on custom View Android Example

Draw path on custom View Android Example

Create MyView.java

public class MyView extends View {

 Paint paint;

 Path path;

 public MyView(Context context) {

  super(context);

  init();

 }

 public MyView(Context context, AttributeSet attrs) {

  super(context, attrs);

  init();

 }

 public MyView(Context context, AttributeSet attrs, int defStyle) {

  super(context, attrs, defStyle);

  init();

 }

 private void init() {

  paint = new Paint();

  paint.setColor(Color.BLUE);

  paint.setStrokeWidth(10);

  paint.setStyle(Paint.Style.STROKE);

  path = new Path();

  path.moveTo(50, 50);

  path.lineTo(50, 500);

  path.lineTo(200, 500);

  path.lineTo(200, 300);

  path.lineTo(350, 300);

 }

 @Override

 protected void onDraw(Canvas canvas) {

  super.onDraw(canvas);

  canvas.drawPath(path, paint);

 }

}

Layout activity_main.xml

<LinearLayout 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"

    android:orientation="vertical"

    tools:context="com.example.androidview.MainActivity" >

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="android-coding.blogspot.com" />

    <com.example.androidview.MyView

        android:layout_width="match_parent"

        android:layout_height="match_parent" />

</LinearLayout>

Create class MainActivity.java

public class MainActivity extends Activity {

 @Override

 protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

 }

}

Draw path on custom View Android Example



That's the articleDraw path on custom View Android Example

That's it for the article Draw path on custom View Android Example this time, hopefully can be useful for all of you. well, see you in another article post.

You are now reading the articleDraw path on custom View Android Example with link addresshttps://inabnonapudyawanabing.blogspot.com/2020/11/draw-path-on-custom-view-android-example.html

0 Response to "Draw path on custom View Android Example"

Post a Comment

Tips Tricks for Android Phone

Tips & Tricks for Android Phone is a free android app and Collection of Tips and Tricks related to using your android mobile device lik...