Last active
July 26, 2017 21:31
-
-
Save Evin1-/33965fd6456d1ddf1f40d44d2c742ab9 to your computer and use it in GitHub Desktop.
Minimal CustomView
This file contains 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" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context="com.example.myapplication.MainActivity"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Hello World!" /> | |
<com.example.myapplication.CustomRectangle | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</LinearLayout> |
This file contains 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
public class CustomRectangle extends View { | |
private Rect rectangle; | |
private Paint paint; | |
public CustomRectangle(Context context, @Nullable AttributeSet attrs) { | |
super(context, attrs); | |
rectangle = new Rect(100, 100, 300, 250); | |
paint = new Paint(); | |
paint.setColor(Color.YELLOW); | |
} | |
@Override | |
protected void onDraw(Canvas canvas) { | |
super.onDraw(canvas); | |
canvas.drawColor(Color.BLUE); | |
canvas.drawRect(rectangle, paint); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment