अंदर खींचें करने के लिए एक बाँधा हुआ मैं RelativeLayout अंदर एक खींचने योग्य दृश्य पैदा की है। लेकिन ऐसा लगता है कि रिलेवेटिवआउट से परे है।RelativeLayout
मैं बस एक दृश्य ViewGroup
अंदर खींचने योग्य बनाना चाहते और इस दृश्य स्क्रीन के अनुसार draggable
है। और यह RelativeLayout की सीमाओं से परे खींचने योग्य है। मैं रिलेवेटिवआउट के भीतर ड्रैगगेबल रहने के लिए इसे कैसे प्रतिबंधित कर सकता हूं।
CustomImageButton
public class ImageButtonCustom extends ImageButton implements View.OnTouchListener{
float dX, dY;
private RelativeLayout rootView;
private ImageButtonCustom imageButtonCustom;
private OnMoveListener onMoveListener;
public ImageButtonCustom(Context context,RelativeLayout rootView){
super(context);
this.rootView = rootView;
init();
}
public ImageButtonCustom(Context context) {
super(context);
init();
}
public ImageButtonCustom(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public ImageButtonCustom(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init(){
imageButtonCustom = this;
setImageResource(R.drawable.upper_left);
setBackgroundColor(Color.TRANSPARENT);
setOnTouchListener(this);
/*RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
rl.addRule(RelativeLayout.ALIGN_BOTTOM);*/
rootView.addView(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
dX = v.getX() - event.getRawX();
dY = v.getY() - event.getRawY();
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
v.animate()
.x(event.getRawX() + dX)
.y(event.getRawY() + dY)
.setDuration(0)
.start();
//no use of ViewPositionUtil
onMoveListener.onMove(new Position());//positionXY);
break;
}
rootView.invalidate();
return true;
}
public void setOnMoveListener(OnMoveListener onMoveListener){
this.onMoveListener = onMoveListener;
}
public float getCenterX(){
return getX() + getWidth()/2;
}
public float getCenterY(){
return getY() + getHeight()/2;
}
public interface OnMoveListener{
void onMove(Position positionXY);
}
}
संपादित करें:
ImageButton खींचने योग्य है लेकिन यह outside of parent
चला जाता है। को अपने मूल लेआउट के भीतर खींचने के लिए प्रतिबंधित करें।
भी कोशिश की http://stackoverflow.com/ प्रश्न/21662397/कैसे-से-रखने-एक-छवि-भीतर-लेआउट-साथ-ड्रैग-एंड-ड्रॉप – Nepster