大家好我想让我的DrawingSurface视图透明.我试了很多东西,但它不起作用.
这是我的表面视图透明的xml代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/icon" >
</ImageView>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000" >
<codewalla.android.drawings.DrawingSurface
android:id="@+id/drawingSurface"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</codewalla.android.drawings.DrawingSurface>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/colorRedBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="R" />
<Button
android:id="@+id/colorBlueBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="G" />
<Button
android:id="@+id/colorGreenBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="B" />
<Button
android:id="@+id/undoBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="U" />
<Button
android:id="@+id/redoBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="10"
android:onClick="onClick"
android:text="R" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我有一个带有背景图像的画布。我需要知道是否有可能清除此画布上的涂料以重绘而不清除其背景图像。这是我的示例以及到目前为止的结果。
爪哇
public void setCanvas() {
if(mFile != null && mFile.exists()) {
mPictureBitmap = BitmapFactory.decodeFile(mFile.getAbsolutePath());
mBitmap = Bitmap.createScaledBitmap(mPictureBitmap, mImageView.getWidth(), mImageView.getHeight(), false);
mBitmap = mBitmap.copy(Bitmap.Config.ARGB_8888, true);
mCanvas = new Canvas(mBitmap);
mImageView.setImageBitmap(mBitmap);
mImageView.setOnTouchListener(this);
}
}
private void draw() {
mCanvas.drawColor(Color.TRANSPARENT, Mode.CLEAR); // THIS LINE CLEARS
int lastIndex = mCordHashMap.size() - 1;
int index = 0;
for (LinkedHashMap.Entry<String, ArrayList<Circle>> entry : mCordHashMap.entrySet()) {
ArrayList<Circle> coords = new ArrayList<Circle>();
coords = entry.getValue();
Path path = new Path();
String key = entry.getKey();
String surface = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 onTouch 侦听器在表面视图上绘图,但是我得到了奇怪的绘图(线条的边缘自行移动),如下面的 GIF 所示:
这是我的代码:
public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback {
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
Canvas canvas;
private Path path;
Paint mPaint = new Paint();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
surfaceView = (SurfaceView) findViewById( R.id.surfaceView );
surfaceHolder = surfaceView.getHolder();
surfaceView.getHolder().addCallback( this );
canvas = surfaceView.getHolder().lockCanvas();
mPaint = new Paint();
mPaint.setAntiAlias( true );
mPaint.setDither( true );
// mPaint.setColor(0xff000000);
mPaint.setStyle( Paint.Style.STROKE );
mPaint.setStrokeJoin( Paint.Join.ROUND);
mPaint.setStrokeCap( Paint.Cap.ROUND);
mPaint.setStrokeWidth( 50);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public …Run Code Online (Sandbox Code Playgroud) 我是 android 开发的菜鸟,我遇到了问题。我正在尝试使用 SurfaceView 制作一个简单的游戏。但是在我启动应用程序时从未调用过surfaceCreated。
我正在使用他的答案在背景中使用较少的内存 这里是放置 setcontentView 的位置:
call_surfaceView = new class_surfaceView(cMainActivity);
// Setup your SurfaceView
SurfaceView surfaceView = call_surfaceView; // use any SurfaceView you want
surfaceView.setZOrderOnTop(true);
surfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT);
// Setup your ImageView
ImageView bgImagePanel = new ImageView(cMainActivity);
bgImagePanel.setBackgroundResource(R.drawable.background); // use any Bitmap or BitmapDrawable you want
// Use a RelativeLayout to overlap both SurfaceView and ImageView
RelativeLayout.LayoutParams fillParentLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
RelativeLayout rootPanel = new RelativeLayout(cMainActivity);
rootPanel.setLayoutParams(fillParentLayout);
rootPanel.addView(bgImagePanel, fillParentLayout);
rootPanel.addView(surfaceView, fillParentLayout);
setContentView(rootPanel);
Run Code Online (Sandbox Code Playgroud)
这是我的surfaceView代码:
import android.content.Context; …Run Code Online (Sandbox Code Playgroud)