how to make this thing work?
lectricas opened this issue · 7 comments
ViewMover mover = ViewMoverFactory.createInstance(movable1);
MovingParams params = new MovingParams(getContext(), 100.0f, 100.0f);
mover.move(params);
where movable1 is my TextView.
Nothing happens, except strange logging info...
Can you provide some more examples?
Hi lectricas
Your code block for moving the view looks OK
However there are many cases, which may cause your app to behave not as you may expect
Could you please post here the code of layout instantiation and the code where you call the provided code block?
Yep. I'm doing it with butterknife. Is it now allowed?
View root = inflater.inflate(R.layout.fragment_level_three, container, false); //where fragment_level_three is a FrameLayout
ButterKnife.bind(this, root);
It should work
What is the target API?
Post please the code block of how and where do you call the moving of the TextView
package com.pythonanywhere.example.logosanimals.view.level;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.pythonanywhere.polusov.logosanimals.R;
import com.pythonanywhere.polusov.logosanimals.util.Tools;
import com.pythonanywhere.polusov.logosanimals.view.BaseLevelFragment;
import com.software.shell.viewmover.configuration.MovingParams;
import com.software.shell.viewmover.movers.ViewMover;
import com.software.shell.viewmover.movers.ViewMoverFactory;
import java.util.Random;
import butterknife.Bind;
import butterknife.ButterKnife;
public class LevelThreeFragment extends BaseLevelFragment {
@Bind(R.id.movable1)
TextView movable1;
@Bind(R.id.frame_for)
FrameLayout frameFor;
public static final int LEVEL = 3;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_level_three, container, false);
ButterKnife.bind(this, root);
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
Log.d("MyFragment", "size.x:" + size.x);
Random random = new Random();
for (int i = 0; i < 3; i++) {
TextView textView = new TextView(getActivity());
textView.setX(random.nextInt(size.x - 100));
textView.setY(random.nextInt(size.y - 100));
textView.setText(i+"dsf");
frameFor.addView(textView);
}
ViewMover mover = ViewMoverFactory.createInstance(movable1);
MovingParams params = new MovingParams(getContext(), 100.0f, 100.0f);
mover.move(params);
// movable1.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View view, MotionEvent event) {
//
// FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) view.getLayoutParams();
// if (view.getId() != R.id.movable1) return false;
//
// Log.d("MyFragment", event.getAction() + "event.getRawX():" + event.getRawX() + "Y" + event.getRawY());
//
// switch (event.getAction()) {
// case MotionEvent.ACTION_MOVE:
// params.topMargin = (int) event.getRawY() - view.getHeight();
// params.leftMargin = (int) event.getRawX() - (view.getWidth() / 2);
// view.setLayoutParams(params);
// break;
//
//// case MotionEvent.ACTION_UP:
//// params.topMargin = (int) event.getRawY() - view.getHeight();
//// params.leftMargin = (int) event.getRawX() - (view.getWidth() / 2);
//// view.setLayoutParams(params);
//// break;
////
// case MotionEvent.ACTION_DOWN:
// view.setLayoutParams(params);
// break;
// }
//
// return true;
// }
// });
return root;
}
public static LevelThreeFragment newInstance() {
return new LevelThreeFragment();
}
@Override
public void onDestroyView() {
super.onDestroyView();
ButterKnife.unbind(this);
}
}
you can just make a sample main activity to demonstrate how it should be done
At first look I may assume that moving works, however when you launch the app you see only the result of the movement, but not the moving process. This happens because the moving code block is executed before the fragment is shown
The goal of moving indeed is that it should be performed on a certain action when your UI is responsive, e.g. you may create a button and assign a moving process to its onClick event
Please try it with button firstly
Also there is a fragment and its unclear now how it is instantiated, so I would also suggest you to try movement from a simple Activity with FrameLayout
Please let me know if this helps