Thursday, March 21, 2013

e. How to give a zoomable picture in an Application

Zoomable pictures are only supported in Webview and Mapview. So first we have to create a Webview layout with zoom controls in it.
First copy the picture in to the assets folder
Then, Copy the following code in to activity_main.xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapActivity" >
       
       
        <ZoomControls
            android:id="@+id/zoomControls1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="52dp"
            android:layout_marginRight="20dp" />

        <WebView
            android:id="@+id/webView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"           
            android:layout_alignParentTop="true"
             />

</RelativeLayout>


Now vopy the following code in the oncreate method,in ActivityMain.Java file

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map);
        // Show the Up button in the action bar.
        //getActionBar().setDisplayHomeAsUpEnabled(true);
       
        WebView WV = (WebView)findViewById (R.id.webView1);
        WV.loadUrl("file:///android_asset/kerala.jpg");
        WV.getSettings().setBuiltInZoomControls(true);
        WV.getSettings().setSupportZoom(true);
         
    }


You are done.Dont forget to replace the kerala.jpg file name with your filename of picture. Just run the application yoiu will find the picture as zoomable.

2 comments:

  1. Zoomable picture is good fun and android application developers can develop this according to the requirement. This xml file help for the same one. Great one.

    ReplyDelete
  2. This page is insightful and helpful. Lots of people will assert that everything in your site is great. asp.net training in jalandhar

    ReplyDelete

Please give your valuable comments so as to know whether this blog is useful to you.You can also write helpful Android Development Syntax or Shortcuts or Tips.