//In LegelPlex i faced a problem of ,my image on WebView is not Centered after ZoomOut.It //just placed //on top of the Screen not at Center of the screen .So, i fixed that issue using below code in LegelPlex Proj..
ShowImageFile.java:-
package com.dharani.android.legalplex.PresentationLayer;
import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.ImageView;
import com.dharani.android.legalplex.R;
import com.dharani.android.legalplex.SharedVariables;
public class ShowImageFile extends Activity {
WebView webView1;
// Dialog mDialog;
int height1,width1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_image_file);
ImageView details_close_btn=(ImageView) findViewById(R.id.showimage_close_btn);
details_close_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
webView1=(WebView) findViewById(R.id.webView1);
webView1.getSettings().setBuiltInZoomControls(true);
webView1.setInitialScale(1);
Bundle b=null;
b=getIntent().getExtras();
try{
if(b!=null)
{
String path=b.getString("imageuri");
Log.d("show image","image url"+path);
File imgFile = new File(path);
Log.d("HI1","local url"+path);
if(imgFile.exists()){
loadHTML(path);
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
public void loadHTML(String path) {
System.out.println("----------path1=="+SharedVariables.imagesExternalStroageLocationFilePath+"/LegalPlex");
System.out.println("----------path2=="+path);
System.out.println("----------path3=="+SharedVariables.imagesExternalStroageLocation.getAbsolutePath());
/*BitmapFactory.Options options = new BitmapFactory.Options();
// will results in a much smaller image than the original
options.inSampleSize = 8;
Bitmap b = BitmapFactory.decodeFile(path,options);
ImageView imageView=(ImageView)findViewById(R.id.imageView);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(b);
*/
/*Display d = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = d.getWidth();
int height = d.getHeight();
System.out.println("----------width=="+width); //- 320
System.out.println("----------height=="+height);//- 480
*/
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height =metrics.heightPixels;
int width=metrics.widthPixels;
System.out.println("----------width=="+width); //-320
System.out.println("----------height=="+height);//-480
/*float xdpi=getResources().getDisplayMetrics().xdpi;
float ydpi=getResources().getDisplayMetrics().ydpi;
System.out.println("----------width=="+xdpi);//-160
System.out.println("----------height=="+ydpi);//-160
float px = width * (xdpi / 160);
float px1 = width / (xdpi / 160);
System.out.println("----------px=="+px);
System.out.println("----------px1=="+px1);*/
String html = new String();
html = ("<html><BODY ><table align='center'><tr><td><img src=\""+path+"\" width=\""+width*3+"px\" height=\""+height*2+"px\" ></td></tr></table> </BODY></html>" );
webView1.loadDataWithBaseURL("file:///sdcard/data/data/com.dharani.android.nycparkinghero.Views/",
html,
"text/html",
"utf-8",
"");
}
}
show_image_file.xml:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/showevidenceimagerootlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/activityBg"
android:orientation="vertical"
android:weightSum="1" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="52dip"
android:background="@drawable/toolbarx" >
<ImageView
android:id="@+id/showimage_close_btn"
android:layout_width="36dip"
android:layout_height="36dip"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_marginRight="4dip"
android:src="@drawable/close_new_button" />
<ImageView
android:layout_width="3dip"
android:layout_height="50dip"
android:layout_toRightOf="@+id/showimage_close_btn"
android:src="@drawable/linex" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/relativeLayout1"
android:layout_marginTop="30dip"
android:layout_marginBottom="30dip"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:gravity="center">
<WebView
android:id="@+id/webView1"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</RelativeLayout>
Comments
Post a Comment