Closed konopkoman closed 3 months ago
Are you using a custom drag item? You need to use that as otherwise it will just use a screenshot of the view which does not work with clipToOutline I think.
Are you using a custom drag item? You need to use that as otherwise it will just use a screenshot of the view which does not work with clipToOutline I think.
In my list adapter I use DragItemAdapter
, and DragItemAdapter.ViewHolder
as view holder
Ok, check the sample app, that is using a custom view.
private void setupListRecyclerView() { mDragListView.setLayoutManager(new LinearLayoutManager(getContext())); ItemAdapter listAdapter = new ItemAdapter(mItemArray, R.layout.list_item, R.id.image, false); mDragListView.setAdapter(listAdapter, true); mDragListView.setCanDragHorizontally(false); mDragListView.setCanDragVertically(true); mDragListView.setCustomDragItem(new MyDragItem(getContext(), R.layout.list_item)); }
Then you need to bind it as well.
private static class MyDragItem extends DragItem {
MyDragItem(Context context, int layoutId) {
super(context, layoutId);
}
@Override
public void onBindDragView(View clickedView, View dragView) {
CharSequence text = ((TextView) clickedView.findViewById(R.id.text)).getText();
((TextView) dragView.findViewById(R.id.text)).setText(text);
dragView.findViewById(R.id.item_layout).setBackgroundColor(dragView.getResources().getColor(R.color.list_item_background));
}
}
Thank you for fast responce, but it seems to MyDragItem
class never called when dragging (an item looks like an empty view while dragging, it stay completely invisible).
protected open fun setupList(){
//some code here
val columnSource = ColumnProperties.Builder.newBuilder(adapterSource)
.setLayoutManager(LinearLayoutManager(this))
.setHasFixedItemSize(true)
.setColumnBackgroundColor(Color.TRANSPARENT)
.setHeader(bindingSourceListHeader.root)
.build()
val columnTarget = ColumnProperties.Builder.newBuilder(adapterTarget)
.setLayoutManager(LinearLayoutManager(this))
.setHasFixedItemSize(true)
.setColumnBackgroundColor(getColor(R.color.train_builder_list_column_target))
.setHeader(bindingTargetListHeader.root)
.build()
binding.boardView.addColumn(columnTarget)
binding.boardView.addColumn(columnSource)
binding.boardView.setCustomDragItem(MyDragItem(this, R.layout.list_item_wagon_draggable)) //set custom view
binding.boardView.setBoardListener(object : BoardView.BoardListenerAdapter(){
override fun onItemChangedColumn(oldColumn: Int, newColumn: Int){
viewModel.setTargetList(adapterTarget.getItems())
}
override fun onItemDragEnded(fromColumn: Int, fromRow: Int, toColumn: Int, toRow: Int){
Timber.d("test onItemChangedPosition oldColumn = $fromColumn, newColumn = $toColumn")
if (fromColumn == 0 && toColumn == 0)
viewModel.setTargetList(adapterTarget.getItems())
}
})
}
private inner class MyDragItem(context: Context, layoutId: Int): DragItem(context, layoutId) {
override fun onBindDragView(clickedView: View, dragView: View) {
Timber.d("test DragItem onBindDragView") //not called
}
override fun onStartDragAnimation(dragView: View?) {
super.onStartDragAnimation(dragView)
Timber.d("test DragItem onStartDragAnimation ") //not called
}
}
Hm ok, that is weird, can you get the sample project to work?
Ok I see the problem now, you need to set the custom drag item before you add the columns. Not so easy to know, but that is how it is.
You need to set the custom drag item before you add the columns. Not so easy to know, but that is how it is.
It works, thank you. But here is one thing. I still can't set a TextView value in my dragView
while my XML layout builded using DataBinding. To make dragging layout data visible, I had to create new separate layout without DataBinding.
Hm ok, I have not tested with databinding, I just update the value in the onBind method
Succeed! The issue can be closed.
Hey! List item clipToOutline doesn't work when dragging. Please look at picture. Here I use LinearLayout background with rounded corners. When static it looks as expected, but when dragging an item, corners don't rounded until I drop the item. Any thoughts?
Android API 32, lib 1.7.2 (currently can't use the latest version due to project restrictions).