我使用webview从sdcard加载图像它工作正常但是当我点击一个按钮将webview转换为180度时,webview就会消失,但是当我再次按下它时,webview就可见了。 我尝试在运行时以prgrammatically方式更改layout_width和height,但它不起作用。
MY Xml:
<nidhinkumar.pencilruler.helper.MywebView
android:id="@+id/full_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
/>
代码:
public class TeacherViewImage extends Activity{
TextView text,imagename,imagecount,done;
ImageButton btnback,rotate,landrotate;
Button draw,zoom,undo,redo,clear,rotatez;
float initialScale;
int position;
String[] filepath;
String[] filename;
MywebView wx;
Bitmap b;
FrameLayout frame;
ProgressDialog pg;
int count=0;
ImageView img;
int width,height;
float angle=0;
final Context context=this;
LayoutAnimationController animController;
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
wx.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
// Restore the state of the WebView
wx.restoreState(savedInstanceState);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.teacherview_newimage);
Intent i = getIntent();
// Get the position
position = i.getExtras().getInt("position");
// Get String arrays FilePathStrings
filepath = i.getStringArrayExtra("filepath");
// Get String arrays FileNameStrings
filename = i.getStringArrayExtra("filename");
count=position+1;
// Locate the TextView in view_image.xml
text = (TextView) findViewById(R.id.imagetext);
// Load the text into the TextView followed by the position
text.setText(filename[position]);
// Locate the ImageView in view_image.xml
img=new ImageView(this);
imagecount=(TextView)findViewById(R.id.sheetevalimagename);
imagecount.setText("Page"+count);
draw=(Button)findViewById(R.id.teacherbtndraw);
zoom=(Button)findViewById(R.id.teacherbtnzoom);
clear=(Button)findViewById(R.id.teacherbtnclear);
undo=(Button)findViewById(R.id.teacherbtnundo);
redo=(Button)findViewById(R.id.teacherbtnredo);
rotatez=(Button)findViewById(R.id.teacherbtnorientation);
done=(TextView)findViewById(R.id.teacherbtndone);
frame=(FrameLayout)findViewById(R.id.frmlayout);
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
width = displayMetrics.widthPixels;
height = displayMetrics.heightPixels;
btnback=(ImageButton)findViewById(R.id.teacherviewimageback);
btnback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(TeacherViewImage.this,TeacherCorrectMainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
});
//imageview = (ImageView) findViewById(R.id.full_image_view);
pg=new ProgressDialog(TeacherViewImage.this);
//rotate=(Button)findViewById(R.id.rotate);
wx = (MywebView) findViewById(R.id.full_image_view);
wx.setBackgroundColor(0);
//wx.getSettings().setBuiltInZoomControls(true);
wx.getSettings().setUseWideViewPort(true);
//wx.setDrawingCacheEnabled(true);
WebSettings webSettings = wx.getSettings();
//wx.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
if (savedInstanceState == null)
{
wx.loadUrl("file:///" + filepath[position]);
}
wx.loadUrl("file:///" + filepath[position]);
//wx.setDrawingCacheEnabled(false);
// picView.setOnClickListener();
//wx.setInitialScale(68);
wx.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
wx.setDrawingCacheEnabled(true);
wx.getSettings().setSupportZoom(true);
wx.getSettings().setBuiltInZoomControls(true);
wx.getSettings().setDisplayZoomControls(false);
wx.setPadding(0, 0, 0, 0);
wx.getSettings().setLoadWithOverviewMode(true);
//wx.getSettings().setUseWideViewPort(true);
wx.setWebViewClient(new WebViewClient()
{
@Override
public void onPageFinished(WebView view, String url)
{
TeacherViewImage.this.initialScale = wx.getScale();
}
});
rotatez.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imagecount.setText("Rotation-Enabled");
v.setSelected(!v.isSelected());
// wx.allowzooming=false;
// wx.allowdrawing=false;
// wx.onRotate();
angle+=180;
if(angle==180){
ViewGroup.LayoutParams vc=wx.getLayoutParams();
vc.height=width;
vc.width=height;
wx.setLayoutParams(vc);
}
wx.setRotation(angle);
// wx.setLayoutAnimation(animController);
}
});
draw.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imagecount.setText("Draw ");
v.setSelected(!v.isSelected());
wx.allowzooming=false;
// wx.allowdrawing=true;
wx.allowdrawing=v.isSelected();
wx.getSettings().setSupportZoom(false);
wx.getSettings().setBuiltInZoomControls(false);
wx.getSettings().setDisplayZoomControls(false);
}
});
zoom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imagecount.setText("Zoom Enabled");
v.setSelected(!v.isSelected());
wx.allowdrawing=false;
wx.allowzooming=v.isSelected();
wx.getSettings().setSupportZoom(true);
wx.getSettings().setBuiltInZoomControls(true);
wx.getSettings().setDisplayZoomControls(false);
wx.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
wx.setDrawingCacheEnabled(true);
}
});
undo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imagecount.setText("Undo");
wx.onClickUndo();
}
});
redo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imagecount.setText("Redo");
wx.onClickRedo();
}
});
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imagecount.setText("Page"+count);
wx.reset();
}
});
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showInputDialog();
}
});
}
答案 0 :(得分:0)
尝试在onCreate()
:
wx.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
如果您愿意,可以将其设置为xml文件,如下所示:
<nidhinkumar.pencilruler.helper.MywebView
android:id="@+id/full_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layerType="software"
/>