小编Vla*_*nya的帖子

用多种颜色绘制路径

我正在使用 android.graphics.Path 在 android.graphics.Canvas 上绘图。我希望允许用户使用一系列颜色和笔划宽度进行绘制,但是,每当颜色或笔划宽度发生更改时,所有内容都会使用新的颜色或笔划宽度重新绘制。我怎样才能解决这个问题?

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/activity_main"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:id="@+id/btnW10"
            android:layout_margin="3sp"
            android:layout_weight="1"
            android:text="Width10"/>
        <Button
            android:id="@+id/btnW40"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3sp"
            android:layout_weight="1"
            android:text="Width40"/>
        <Button
            android:id="@+id/btnW70"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3sp"
            android:layout_weight="1"

            android:text="Width70"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="20dp"></LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3sp"
            android:layout_weight="1"
            android:id="@+id/btnBlue"
            android:text="Blue"/>
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3sp"
            android:layout_weight="1"
            android:id="@+id/btnRed"
            android:text="Red"/>
        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="3sp"
            android:layout_weight="1"

            android:id="@+id/btnGreen"
            android:text="Green"/>

    </LinearLayout>

    <com.vladislav.canvaswc.DrawLine
        android:id="@+id/drwLine"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

main.java: …

java android canvas

5
推荐指数
1
解决办法
1909
查看次数

标签 统计

android ×1

canvas ×1

java ×1