我有一个Android应用程序,用户在照片上绘制,移动和重塑一些对象.在此页面中,我的屏幕布局包括加载的照片和在其下方(纵向视图)的一些按钮.我的视图看起来与我想要的xml如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/linear" >
<LinearLayout
android:id="@+id/buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentBottom="true">
<ImageView
android:id="@+id/draw"
android:layout_width="80dp"
android:layout_height="50dp"
android:clickable="true"
android:src="@drawable/draw"/>
<ImageView
android:id="@+id/delete"
android:layout_width="80dp"
android:layout_height="50dp"
android:clickable="true"
android:layout_toRightOf="@+id/erase"
android:src="@drawable/delete"/>
<ImageView
android:id="@+id/done"
android:layout_width="80dp"
android:clickable="true"
android:layout_height="50dp"
android:layout_toRightOf="@+id/delete"
android:src="@drawable/done"/>
</LinearLayout>
<ImageView
android:id="@+id/photo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_above="@id/buttons"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
问题是我希望按钮始终位于绘制对象的顶部.现在,如果用户绘制一条线然后以一条边缘将低于图像的方式移动它,则该线将在按钮上方.在那一点上它是不可触摸的,因为画布被设置为具有我的图像的位图,但它将是可见的.如果线的一部分离开屏幕,我希望它以消失的方式消失.
我该如何实现呢?是否有一些属性可以确保这些按钮始终位于绘制的对象上?先感谢您!
当在一个元素使的用单个手指滑动手势,浏览器将会触发wheel事件,而不是touchmove或mousemove事件.如何停止车轮行为,并允许单个手指始终被视为触摸/鼠标移动?
因此,我想将单指滑动视为一系列mousemove或touchmove代替wheel事件.如果在此元素上滑动,我根本不想用单指滑动来滚动页面.这在Chrome和IE11中很容易实现.这在Firefox中现在似乎不可能.目前我认为这是一个错误,但可能有一些我遗漏的东西.
这是一个简单的例子:
http://codepen.io/simonsarris/pen/PwbdRZ
var can = document.getElementById('can');
can.addEventListener('mousemove', function(e) {
// Will never happen on the Surface Pro 3 in Firefox
// Will happen in IE11 though
console.log('mouseMove')
});
can.addEventListener('touchmove', function(e) {
// Will never happen on the Surface Pro 3 in Firefox
// Will happen in Chrome though
console.log('touchMove')
});
// Stops the window from scrolling in firefox when you swipe on the …Run Code Online (Sandbox Code Playgroud) Razor 组件和页面都有OnAfterRender生命周期方法。当你<SomeComponent>的 中有 时index.razor,首先index.razor会OnAfterRender触发 ,然后SomeComponent.OnAfterRender再触发。
假设在razor页面上你需要做一些工作,但是只能在发生SomeComponent.OnAfterRender火灾之后才能做。这样做的适当方法是什么?
这可能很重要,因为组件的支持 HTML 在其OnAfterRender触发之前尚未准备好(可能不存在)。换句话说,剃刀页面作者如何知道其组件何时相当于 DOM 准备就绪?
如果我有一个画布,我在上面绘制一个像这样的Bitmap:
canvas.drawBitmap(bmLargeImage, srcRect, destRect, paint);
Run Code Online (Sandbox Code Playgroud)
我缩放位图:
canvas.scale(1.5f, 1.5f, 450, 250);
Run Code Online (Sandbox Code Playgroud)
我希望在比例后获得位图的位置.如果比例前的位置是(0,0),那么在比例之后有一个偏移,我需要那个偏移..我怎么能得到它?
谢谢,抱歉这个简单的问题,新手在这里......
我有一张由手绘的城市轮廓组成的 JPEG 图像。我想实现从左到右在空白区域上绘制这些轮廓的缓慢草图效果。如何基于 HTML5 canvas 元素做到这一点?例如将此 JPEG 导入画布并在其上应用一些动画蒙版,或者将 JPEG 重新分解为一组曲线(如果可能的话,我想获得适当工具的列表)并使用简单愚蠢的 ctx.lineTo(...) 和其他曲线函数。
先感谢您。
我通过从View扩展创建了一个自定义View.在onDraw()中,我设法绘制了一些圆圈和其他东西.但是现在我想从资源(SD卡或流)添加背景,这实际上是我从服务器下载的地图,而不是在它上面绘制.它适用于Android 8+
@Override
protected void onDraw(Canvas canvas) {
Canvas g = canvas;
String file = "/mnt/sdcard/download/tux.png";
Bitmap bg = null;
try {
bg = BitmapFactory.decodeFile(file);
g.setBitmap(bg);
} catch (Exception e) {
Log.d("MyGraphics", "setBitmap() failed according to debug");
}
}
Run Code Online (Sandbox Code Playgroud)
不知怎的,g.setBitmap(BG)不断失败,我没有看过的图像规格,但实际上它只是一个晚礼服的图像PNG格式的(无24位色).有人可以给我一些如何添加背景图片的技巧,以便我可以在上面绘图吗?谢谢.
我知道android中的画布是一个较低级别的绘图表面但是当前我在画布中绘制了所有对象,我希望有更好的方法来处理画布上每个对象的点击.我尝试通过它们绘制的视图匹配x和y,并且只在某些时候有效.
反正有没有让单个位图我画我的画布可点击.我的应用程序中的对象正在动态移动...想想屏幕元素移动的游戏对象.我已经尝试创建一个扩展Button的类,但是所有内容都被绘制在屏幕的右上角所以我不确定你是否可以在屏幕上移动对象扩展按钮,但至少当我点击堆栈顶部的图像时它给出了预期的回应.现在我通过绘制画布的视图注册屏幕点击,并通过运行循环使屏幕操作发生我有一个所有项目的数组,当点击注册时,我遍历所有项目和那些是在屏幕上检查他们的坐标.如果我得到了一个匹配,我就会发出一个意图来执行一个动作.....就像我说的那样充其量是不可靠的,我暂时不知道如何重组所有内容以获得可靠的响应.
您好我正在开发一个wpf应用程序.我在画布中添加了myUserControl的对象.我需要高度和添加usercontrol.现在的问题是用户控件是动态设计的,我创建网格并根据用户的配置添加行和列,并且我在高度和宽度上给出auto.所以我在画布中添加它时没有获得用户控件的实际高度和宽度.
我想学习如何在画布上绘制垂直文本.对不起,也许是愚蠢的问题,但我无法解决这个问题.我可以这样做:
if (i ==10)
{
this_str2 = "0.00";
}
canvas.save();
canvas.rotate(-90,190,90);
canvas.drawText(this_str2, x_guide +50, drawSizes[1] + drawSizes[3] - (i * drawSizes[3] / 10) +20, paint);
canvas.restore();
}
Run Code Online (Sandbox Code Playgroud)
但它没有在X上正确显示,而Y是这个问题的任何其他解决方案7
我无法找到答案.考虑下面的剪辑代码:
boolean is_ok = mycanvas.clipRect(clip_left, clip_top, clip_right+1, clip_bottom+1);
mycanvas.getClipBounds(clipRect);
if (!is_ok ||
clipRect.left != clip_left ||
clipRect.top != clip_top ||
clipRect.right != clip_right+1 ||
clipRect.bottom != clip_bottom+1)
{
Log.i("DEBUG", "setClipping failed");
}
Run Code Online (Sandbox Code Playgroud)
返回剪辑边界时,它们与刚刚设置的不匹配.例如,如果clip_left,clip_top,clip_right,clip_bottom是(100,50,109,59),那么在给定上面的代码的情况下,我希望剪裁边界是(100,50,110,60).事实并非如此.getClipBounds()返回(100,51,110,60).
当我将它设置为50时,为什么top = 51?还有一些我不明白的东西.