我有一个应用程序,我需要在其中移动成堆的按钮(就像将一叠卡片的一部分从一堆移动到另一堆)。我已经在 xml 布局中定义了所有按钮,并为所有按钮设置了触摸和拖动监听器。 我可以在屏幕上单独拖放任何按钮。但在某些情况下我需要做的是拖动堆叠在我同时单击的原始按钮顶部的其他按钮。 有没有办法“欺骗”或模拟按下另一个按钮(以便听众注册它)? 谢谢 ***编辑于 2015 年 9 月 8 日 @覆盖 public boolean onTouch(View v, MotionEvent e) { //tosty("mclicking: "+mClicking); int 开始位置 = 0; 开关(e.getAction()和MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN:
isWastePile=false;
get_selected_deck(v); // determines which of 7 decks or layouts in the tablau you have
// clicked
FromDeck = selecteddeck;
FromDeckCard = deckcard;
FromDeckButton = deckbutton;
// if (!mClicking) {
mClicking = true;
//String piecetag = (String) v.getTag();
// // IDEA!!!/ ///
/*
* I wrote a function that finds all the ImageButtons below where
* the user clicked, and set them all to invisible. I then created a
* new Linear Layout within the Linear Layout that the user clicked (during the ACTION_DOWN event),
* and passed that into the Drag Shadow builder during the ACTION_MOVE event.
*
* Once into the ACTION_DROP portion, I simply referenced global
* variables to figure out if the user dropped in one or multiple
* ImageButtons, and dealt with them accordingly.
*/
//if (!isWastePile) {
//draglayout.setClipChildren(false);
lltemp = new LinearLayout(this);
lltemp.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams llparams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llparams.setMargins(0, -52, 0, 0);
lltemp.setLayoutParams(llparams);
draglayout.addView(lltemp);
for (int i = 0; i < deckstack_list[selecteddeck].size(); i++) {
if (v == (draglayout.getChildAt(i))) {
startpos = i;
for (int o = i; o < deckstack_list[selecteddeck].size(); o++) {
// layout5.removeViewAt(o);
draglayout.getChildAt(o).setVisibility(View.GONE); // all
// buttons
// being
dragtempstack.push((Integer) deckstack_list[selecteddeck].get(o)) ; // dragged
// to
// invisible
// then recreate another linear layout within layout5
// and pass to dragshadow builder
// to do
// also set a GLOBAL variable with stack count (number
// of cards dragged)
lltemp.setClipChildren(false);
lltemp.addView(createtempButtons(o, startpos));
}
}
}
//} // end if wastepile check statement
//tosty("dragtempstack size: "+dragtempstack.size());
break;
case MotionEvent.ACTION_MOVE:
//tosty("Action MOVE");
Log.i("ACTION Event: ", "ACTION MOVE");
// v = layout5;
v = lltemp;
v.setVisibility(View.INVISIBLE);
v.bringToFront();
v.invalidate();
v.setVisibility(View.VISIBLE);
//DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
DeckDragShadow shadowBuilder = new DeckDragShadow(v);
v.startDrag(null, shadowBuilder, v, 0);
correctDrag = false;
break;
private Button createtempButtons(final int i, final int startpos) {
final Button b = new Button(this);
b.setOnTouchListener(this);
b.setOnDragListener(new DeckDragListener());
b.setBackgroundResource(cardimagearray[dragdeckstack.get(i)]);
float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
45, getResources().getDisplayMetrics());
float height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
61, getResources().getDisplayMetrics());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
(int) width, (int) height);
float margTop = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
-36, getResources().getDisplayMetrics());
if (i > startpos) {
params.setMargins(0, -57, 0, 0);
}
b.setLayoutParams(params);
// b.bringToFront();
// b.invalidate();
b.setVisibility(View.VISIBLE);
return b;
最佳答案
与其尝试为每个按钮复制监听器,不如将按钮视为组。当您单击组中的一个按钮时,它会分成两组:上面有按钮的按钮和您要留下的按钮。然后将该组拖放到其他组中。
这些组可以是 LinearLayouts,正如 Templerschaf 所建议的:
这很像 ListView 动画。见:
https://www.youtube.com/watch?v=_BZIvjMgH-Q
关于java - 在java中拖动多个按钮 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32277809/
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我有多个ActiveRecord子类Item的实例数组,我需要根据最早的事件循环打印。在这种情况下,我需要打印付款和维护日期,如下所示:ItemAmaintenancerequiredin5daysItemBpaymentrequiredin6daysItemApaymentrequiredin7daysItemBmaintenancerequiredin8days我目前有两个查询,用于查找maintenance和payment项目(非排他性查询),并输出如下内容:paymentrequiredin...maintenancerequiredin...有什么方法可以改善上述(丑陋的)代
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我有一个具有一些属性的模型:attr1、attr2和attr3。我需要在不执行回调和验证的情况下更新此属性。我找到了update_column方法,但我想同时更新三个属性。我需要这样的东西:update_columns({attr1:val1,attr2:val2,attr3:val3})代替update_column(attr1,val1)update_column(attr2,val2)update_column(attr3,val3) 最佳答案 您可以使用update_columns(attr1:val1,attr2:val2
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试使用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