3

I have a LinearLayout that would contain some other views. I would like to have the ability to zoom in and out on the actual LinearLayout as a whole. Is there a way to do that?

thanks in

user576768
  • 33
  • 3
  • see: http://stackoverflow.com/questions/10013906/android-zoom-in-out-relativelayout-with-spread-pinch and replace relative layout with linearlayout – darkbobo Jul 01 '14 at 19:40

2 Answers2

3

No, sorry, there is nothing built in for zoom on normal widgets, AFAIK. WebView and MapView know how to zoom. Anything else you are on your own.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

I do it that way

MainActivity.java:

public class MainActivity extends Activity
{


Button button;
LinearLayout linearLayout;
Float scale = 1f;
ScaleGestureDetector SGD;
int currentX;
int currentY;




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



    SGD = new ScaleGestureDetector(this, new ScaleListener());



    linearLayout = (LinearLayout) findViewById(R.id.main_container);

}

@Override
public boolean onTouchEvent(MotionEvent event)
{
    SGD.onTouchEvent(event);

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            currentX = (int) event.getRawX();
            currentY = (int) event.getRawY();
            break;
        }

        case MotionEvent.ACTION_MOVE: {
            int x2 = (int) event.getRawX();
            int y2 = (int) event.getRawY();
            linearLayout.scrollBy(currentX - x2 , currentY - y2);
            currentX = x2;
            currentY = y2;
            break;
        }
        case MotionEvent.ACTION_UP: {
            break;
        }
    }

    return true;
}

private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener
{
    @Override
    public boolean onScale(ScaleGestureDetector detector)
    {
        scale = scale * detector.getScaleFactor();
        scale = Math.max(1f, Math.min(scale, 5f)); //0.1f und 5f  //First: Zoom in __ Second: Zoom out
        //matrix.setScale(scale, scale);
        linearLayout.setScaleX(scale);
        linearLayout.setScaleY(scale);

        linearLayout.invalidate();

        return true;
    }

  }

}

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">


<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="zoom_test" />
</LinearLayout>
Roman
  • 318
  • 2
  • 8