2012-03-18 64 views

回答

3

您可以删除布局视图,并将其添加到其他布局(如果这是你在找什么)

ViewGroup oldGroup = (ViewGroup) findViewById(R.id.some_layout); 
ViewGroup newGroup = (ViewGroup) findViewById(R.id.some_other_layout); 

Button button = (Button) oldGroup.findViewById(R.id.a_button); 

oldGroup.removeView(button); 
newGroup.addView(button); 

有没有拖动动画&,它可能会给出奇怪的结果,但它是可能的。

A ViewGroup将是LinearLayoutRelativeLayout和那些。


为了模拟将&丢弃事件,你可以手动调用onDragListener,但有一个问题:

public boolean onDrag(View v, DragEvent event); 

需要一个DragEvent它没有公共的构造函数,所以你只能null

叫它

可能有一种方法可以通过伪造的包创建一个,但这会变得很难看。

private void initializationTest() { 
    DragEvent event = null; 
    /* maybe sth like that 
    Parcel source = Parcel.obtain(); 
    source.writeInt(1234); 
    event = DragEvent.CREATOR.createFromParcel(source); 
    */ 
    onDrag(theTargetView, event); 
} 

另一种可能是创建touchevents,但如果这可能会工作idk。至少monkey可能可以做到这一点。

+0

zapl,他问的是拖放框架。 – 2012-03-18 20:23:54

+0

@imrankhan你可能是对的 – zapl 2012-03-18 20:55:37

+1

非常感谢,我是出于方便的原因寻找第二个答案,因为我的拖放监听器已经完成了我需要完成的一切,我只是不想要太多的冗余代码。由于似乎没有一个简单/优雅的解决方案,我可能需要以另一种方式执行 – Schnodahipfe 2012-03-18 21:39:23

相关问题