Reputation: 15
i'm working on a navigation app in java that draws my steps on a canvas. I want to lock the drawable area of that canvas so my app doesn't draw steps outside of the visible canvas area. Is there a way to lock my canvas? Update : I have the canvas inside a framelayout.
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="359dp"
android:layout_height="379dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginStart="1dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="1dp"
android:background="#2D7DA3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinnerPP"
app:layout_constraintVertical_bias="0.13">
<com.example.uisimplu.Canvas
android:id="@+id/step_surfaceView"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_gravity="center"
android:background="@color/white" />
</FrameLayout>
Upvotes: 0
Views: 104
Reputation: 1481
<?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=".canvasdemo.PaintHomeActivity">
<LinearLayout
android:id="@+id/lll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@id/clear_draw"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/canvas_toolbar" />
</androidx.constraintlayout.widget.ConstraintLayout>
Paste this code in You
LinearLayout layout = findViewById(R.id.lll);
layout.addView(MyPaint);
myPaint is object of Canvas class that's contains onDraw
Upvotes: 2