728x90
안녕하세요 오늘은 DrawingAppLibray를 사용해서 그림판을 빠르게 만들어보도록하겠습니다.
https://github.com/ajithvgiri/canvas.git
1. 라이브러리 등록
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.ajithvgiri:Canvas-Library:v1.1.1'
}
2. XMl 생성
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/parentView"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/btn_clear"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/btn_clear"
android:text="캔버스 비우기"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
3. Java 동작 코드 작성
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
CanvasView canvasView = new CanvasView(MainActivity.this);
binding.parentView.addView(canvasView);
binding.btnClear.setOnClickListener(view -> {
canvasView.clearCanvas();
});
}
}
'안드로이드 자바' 카테고리의 다른 글
[Android][Java] 토스트 메시지 꾸미기 (0) | 2023.01.09 |
---|---|
[Android][Java] Javax로 이메일 전송 기능 구현 (4) | 2023.01.02 |
[Android][Java] AppIntroPage 만들기 (0) | 2022.12.30 |
[Android][Java]Slidinguppanel 사용해서 판넬 만들기 (0) | 2022.12.25 |
[Android][Java]RecyclerView-Selection 라이브러리 사용 (0) | 2022.12.22 |