hi
   I am A Beginner for Android.i created a Layout with 2 views. if i drag 
second layout to top my second layout height should increase.at the same 
time my first layout size should deicer.
(the height changes are based on Drag how much i graded) please help me in 
this.thanks in advance.

my code is like this:

public class DragActivity extends Activity implements View.OnTouchListener {

    LinearLayout clFirstLayout, clSecoundLayout, clMainLayout;
    ScrollView clScroolView;
    /* private static final int SWIPE_MIN_DISTANCE = 120;
     private static final int SWIPE_MAX_OFF_PATH = 250;
     private static final int SWIPE_THRESHOLD_VELOCITY = 200;*/
    private static final int SWIPE_THRESHOLD = 50;
    private static final int SWIPE_VELOCITY_THRESHOLD = 50;

    private GestureDetector gestureDetector;
    View.OnTouchListener gestureListener;
    ActionMode actionMode;
    private float newX = 0;
    private float newY = 0;
    private float oldX = 0;
    private float oldY = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        clScroolView = new ScrollView(this);
        LinearLayout.LayoutParams parms = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
ViewGroup.LayoutParams.FILL_PARENT);
        clScroolView.setLayoutParams(parms);
        clMainLayout = new LinearLayout(this);
        LinearLayout.LayoutParams mainParms = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
ViewGroup.LayoutParams.MATCH_PARENT);
        mainParms.setMargins(5, 5, 5, 5);
        clMainLayout.setLayoutParams(mainParms);
        clMainLayout.setOrientation(LinearLayout.VERTICAL);

        clFirstLayout = new LinearLayout(this);
        LinearLayout.LayoutParams firstParms = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 500, 0.5f);
        firstParms.setMargins(20, 20, 20, 20);
        clFirstLayout.setGravity(Gravity.CENTER);

        clFirstLayout.setBackgroundColor(Color.parseColor("#80F44336"));
        clFirstLayout.setBackgroundColor(Color.TRANSPARENT);
        clFirstLayout.setLayoutParams(firstParms);
        clFirstLayout.setId(R.id.first);

        clFirstLayout.setOrientation(LinearLayout.VERTICAL);

        TextView text = new TextView(this);
        LinearLayout.LayoutParams txtParms = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
ViewGroup.LayoutParams.WRAP_CONTENT);
        txtParms.setMargins(5, 5, 5, 5);
        text.setText("Firsst View");
        text.setGravity(Gravity.CENTER);
        text.setLayoutParams(txtParms);
        clFirstLayout.addView(text);


        clSecoundLayout = new LinearLayout(this);
        LinearLayout.LayoutParams secound = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 500, 0.5f);
        clSecoundLayout.setGravity(Gravity.CENTER);
        clSecoundLayout.setLayoutParams(secound);
        clSecoundLayout.setBackgroundColor(Color.LTGRAY);
        clSecoundLayout.setId(R.id.frame);
        clSecoundLayout.setOrientation(LinearLayout.VERTICAL);
        TextView tvtext = new TextView(this);
        LinearLayout.LayoutParams tvtextParms = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 
ViewGroup.LayoutParams.WRAP_CONTENT);
        tvtextParms.setMargins(5, 5, 5, 5);
        tvtext.setText("Secound View");
        tvtext.setGravity(Gravity.CENTER);
        tvtext.setLayoutParams(tvtextParms);
        clSecoundLayout.addView(tvtext);

        clMainLayout.addView(clFirstLayout);

        clMainLayout.addView(clSecoundLayout);

        setContentView(clMainLayout);
     /*   clFirstLayout.setOnDragListener(new MyDragListener());
        clSecoundLayout.setOnDragListener(new MyDragListener());*/
        clFirstLayout.setOnTouchListener(this);
        clSecoundLayout.setOnTouchListener(this);

//        clSecoundLayout.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View view, MotionEvent motionEvent) {
//                return false;
//            }
//        });
    }
    float dX, dY;
    int iTotalHeight,iHeight;

    @Override
    public boolean onTouch(View view, MotionEvent event) {
        int width = 0, height = 0;
      /*  width = v.getWidth() / 2;
        height = v.getHeight() / 2;*/
        switch (event.getActionMasked()) {

            case MotionEvent.ACTION_DOWN:

                oldX = view.getX() - event.getRawX();
                oldY = view.getY() - event.getRawY();
                break;

            case MotionEvent.ACTION_MOVE:
                newX = event.getX();
                newY = event.getY();
                dX = view.getX() - event.getRawX();
                dY = view.getY() - event.getRawY();
                iHeight = view.getHeight();
                iTotalHeight = 
getWindowManager().getDefaultDisplay().getHeight();
                View.DragShadowBuilder shadowBuilder = new 
View.DragShadowBuilder(null);
                view.setOnDragListener(new MyDragListener());
                view.startDrag(null, shadowBuilder, view, 0);
                view.setOnDragListener(new MyDragListener());

                view.setMinimumHeight((int) dX);

                break;
            default:
                return false;

        }
        return true;
    }
// end of dx==0 if
/*lse{
        if(newX>oldX){
        if(dX>0){
        AbsoluteLayout.LayoutParams params = (AbsoluteLayout.LayoutParams) 
v.getLayoutParams();
// 
relativeLayoutcircleView.getLayoutParams().height=relativeLayoutcircleView.getHeight()-50;
        v.getLayoutParams().width=v.getWidth()-Math.abs((int)dX);
        v.setLayoutParams(params);
        }
        */


    private  void setHeight(float fX,float fY)
    {
        int iFirstHeight,iSecoungHeight;
        iFirstHeight=clFirstLayout.getHeight()/2-(int) fX;
       // iSecoungHeight=clSecoundLayout.getHeight()-Math.abs((int) fY);
          iSecoungHeight=clFirstLayout.getHeight()/2-Math.abs((int)fY);
        //   
clSecoundLayout.getLayoutParams().height=clSecoundLayout.getHeight()+iSecoungHeight;
        
clSecoundLayout.getLayoutParams().height=clSecoundLayout.getHeight()+(int)fY;
       /* if(clSecoundLayout.getLayoutParams().height>700)
            clSecoundLayout.getLayoutParams().height=700;*/
        
clFirstLayout.getLayoutParams().height=clFirstLayout.getHeight()-iSecoungHeight;

        // 
clFirstLayout.getLayoutParams().height=Math.abs(iTotalHeight-clSecoundLayout.getHeight());
      /* clSecoundLayout.setLayoutParams(new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,clSecoundLayout.getHeight()+iFirstHeight));
        clFirstLayout.setLayoutParams(new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,clFirstLayout.getHeight()-iFirstHeight))*/;
        clSecoundLayout.invalidate();
        clFirstLayout.invalidate();

    }


    class MyDragListener implements View.OnDragListener {
      /*  Drawable enterShape = 
getResources().getDrawable(R.drawable.shape_droptarget);
        Drawable normalShape = getResources().getDrawable(R.drawable.shape);
*/
        @Override
        public boolean onDrag(View v, DragEvent event) {
            int action = event.getAction();
           float fX,fY;

            ViewGroup viewgroup = (ViewGroup) v.getParent();
            v.invalidate();

            switch (event.getAction()) {
                case DragEvent.ACTION_DRAG_STARTED:
                    oldX = event.getX();
                    oldY = event.getY();
             //       setHeight(dX,dY);
                    viewgroup.invalidate();
                    break;
                case DragEvent.ACTION_DRAG_ENTERED:

                    viewgroup.invalidate();
                //    setHeight(dX,dY);
                    break;
                case DragEvent.ACTION_DRAG_LOCATION:
                    newX = event.getX();
                    newY = event.getY();
                    dX=newX-oldX;
                    dY=newY-oldY;
                   setHeight(dX,dY);
                    break;
                case DragEvent.ACTION_DROP:
                    newX = event.getX();
                    newY = event.getY();
                    dX=newX-oldX;
                    dY=newY-oldY;
                  //  setHeight(dX,dY);
                    break;
                case DragEvent.ACTION_DRAG_ENDED:
//                v.setBackgroundDrawable(normalShape);
                default:
                    break;
            }




            return true;
        }
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/75305658-eca8-4c29-9418-9a134486a600%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to