我正在尝试在我的 Android 应用程序上使用图像拖动。 我的问题是,当我停止拖动图像时,永远不会调用 DragEvent.ACTION_DROP。
在我的日志猫中,我接到了这个电话:
01-30 13:50:25.003: I/ViewRootImpl(2198): Reporting drop result: false
感谢您的帮助。
这是我的代码:
public class buildImage extends Activity implements OnTouchListener, OnDragListener
{
private LinearLayout slider;
private RelativeLayout board;
@Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.build_image);
//drawing = (SignatureViewModed) findViewById(R.id.myTest);
slider = (LinearLayout) findViewById(R.id.imageSlider);
board = (RelativeLayout) findViewById(R.id.borad);
setImagesSlider();
}
public void setImagesSlider()
{
ImageView image = new ImageView(this);
image.setLayoutParams(new LinearLayout.LayoutParams(100, 100));
Drawable draw = getResources().getDrawable(R.drawable.images);
image.setImageDrawable(draw);
image.setOnDragListener(this);
image.setOnTouchListener(this);
slider.addView(image);
}
@Override
public boolean onTouch(View view, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
ClipData data = ClipData.newPlainText("tests", "test");
DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, shadowBuilder, view, 0);
//view.setVisibility(View.INVISIBLE);
return true;
} else {
return false;
}
}
@Override
public boolean onDrag(View v, DragEvent event) {
// TODO Auto-generated method stub
int action = event.getAction();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
{
Log.i("check6", "check6");
// do nothing
return true;
}
case DragEvent.ACTION_DRAG_ENTERED:
{
Log.i("check4", "check4");
//v.setBackgroundDrawable(enterShape);
return true;
}
case DragEvent.ACTION_DRAG_EXITED:
{
// v.setBackgroundDrawable(normalShape);
Log.i("check3", "check3");
return true;
}
case DragEvent.ACTION_DROP:
// Dropped, reassign View to ViewGroup
Log.i("check", "check");
addNewImage(event);
return true;
case DragEvent.ACTION_DRAG_ENDED:
{
Log.i("check2", "check2");
// addNewImage(event);
return true;
}
default:
break;
}
return true;
}
public void addNewImage(DragEvent event)
{
ImageView image = new ImageView(this);
image.setLayoutParams(new LinearLayout.LayoutParams(100, 100));
Drawable draw = getResources().getDrawable(R.drawable.images);
image.setImageDrawable(draw);
board.addView(image);
float x = event.getX();
float y = event.getY();
image.setX(x);
image.setY(y);
Log.i("margin", "x " + x + " y " + y);
}
}
我的 XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:id="@+id/borad"
android:background="@android:color/darker_gray"
android:layout_above="@+id/temp"
android:layout_height="fill_parent" >
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:id="@+id/temp"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/imageSlider"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
最佳答案
您必须有东西可以放置该图像。到目前为止,图像本身只有一个 OnDragListener。您要放置该图像的位置不包含任何带有 OnDragListener 的控件,因此不会调用您的监听器。
监听 OnDragListeners 的控件不能不可见或消失,因此您必须在单元格看起来为空但实际并非如此的地方放置某种网格。例如带有透明图像的 ImageView。或者将 Alpha 设置为 0f。
至少为您的内部 LinearLayout 设置一个 OnDragListener,然后您将获得 Drop 事件。
关于android - DragEvent.ACTION_DROP 永远不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21455881/
设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案
我知道您通常应该在Rails中使用新建/创建和编辑/更新之间的链接,但我有一个情况需要其他东西。无论如何我可以实现同样的连接吗?我有一个模型表单,我希望它发布数据(类似于新View如何发布到创建操作)。这是我的表格prohibitedthisjobfrombeingsaved: 最佳答案 使用:url选项。=form_for@job,:url=>company_path,:html=>{:method=>:post/:put} 关于ruby-on-rails-rails:Howtomak
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
我有一个rubyonrails应用程序。我按照facebook的说明添加了一个像素。但是,要跟踪转化,Facebook要求您将页面置于达到预期结果时出现的转化中。即,如果我想显示客户已注册,我会将您注册后转到的页面作为成功对象进行跟踪。我的问题是,当客户注册时,在我的应用程序中没有登陆页面。该应用程序将用户带回主页。它在主页上显示了一条消息,所以我想看看是否有一种方法可以跟踪来自Controller操作而不是实际页面的转化。我需要计数的Action没有页面,它们是ControllerAction。是否有任何人都知道的关于如何执行此操作的gem、文档或最佳实践?这是进入布局文件的像素
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
当我执行>rvminstall1.9.2时一切顺利。然后我做>rvmuse1.9.2也很顺利。但是当涉及到ruby-v时..sam@sjones:~$rvminstall1.9.2/home/sam/.rvm/rubies/ruby-1.9.2-p136,thismaytakeawhiledependingonyourcpu(s)...ruby-1.9.2-p136-#fetchingruby-1.9.2-p136-#downloadingruby-1.9.2-p136,thismaytakeawhiledependingonyourconnection...%Total%Rece
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt