mardi 12 mai 2015

How to create an endeless / moveable Layout? "endless paper"-Metapher

how do i create an endless / movable layout, which is endless/movable in all directions? I want to develop an app to create diagrams, and if the diagram gets too big i want it to be movable in all directions.

I hope its understandable.

with regards

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_draw);



        _root = (ViewGroup) findViewById(R.id.draw);
        _view = new ImageView(this);
        _view.setImageResource(R.drawable.greenbutton);
        BitmapDrawable bd=(BitmapDrawable) this.getResources().getDrawable(R.drawable.greenbutton);
        int height=bd.getBitmap().getHeight();
        int width=bd.getBitmap().getWidth();

        /*MyScrollView myV = new MyScrollView(this);
        myV.setLayoutParams(_root.getLayoutParams());*/

        RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(height,width);
        _view.setLayoutParams(layoutParams);

        _view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                final int X = (int) event.getRawX();
                final int Y = (int) event.getRawY();
                switch (event.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_DOWN:
                        RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) v.getLayoutParams();
                        _xDelta = X - lParams.leftMargin;
                        _yDelta = Y - lParams.topMargin;
                        break;
                    case MotionEvent.ACTION_UP:
                        break;
                    case MotionEvent.ACTION_POINTER_DOWN:
                        break;
                    case MotionEvent.ACTION_POINTER_UP:
                        break;
                    case MotionEvent.ACTION_MOVE:
                        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) v.getLayoutParams();
                        layoutParams.leftMargin = X - _xDelta;
                        layoutParams.topMargin = Y - _yDelta;
                        layoutParams.rightMargin = -250;
                        layoutParams.bottomMargin = -250;
                        v.setLayoutParams(layoutParams);
                        break;
                }
                _root.invalidate();
                return true;
            }
        });
        //myV.addView(_view);
        _root.addView(_view);

<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".Draw">


    <RelativeLayout
        android:id="@+id/draw"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/layout_grid">

    </RelativeLayout>


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:orientation="vertical">

        <GridView
            android:id="@+id/mostUsedBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numColumns="2"
            android:layout_weight="1">
        </GridView>
        <GridView
            android:id="@+id/elementBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numColumns="2"
            android:layout_weight="1"></GridView>
        <GridView
            android:id="@+id/relBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:numColumns="2"
            android:layout_weight="1"></GridView>



    </LinearLayout>


</LinearLayout>

Aucun commentaire:

Enregistrer un commentaire