不能在一个对话的中心对齐网页视图图像 [英] Cannot align webview image in centre of a dialog
本文介绍了不能在一个对话的中心对齐网页视图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要对齐图像中的的WebView 以对话的中心。
I want to align image in a webview to the centre of a dialog.
相关code:
void showImageInLargeMode(String link)
{
LayoutInflater inflater=ThirtyArticleDetail.this.getLayoutInflater();
View layout=inflater.inflate(R.layout.showenlargeimagedialog,null);
final Dialog d1 = new Dialog(ThirtyArticleDetail.this);
d1.requestWindowFeature(Window.FEATURE_NO_TITLE);
d1.setContentView(layout);
d1.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
wvdisplayimage=(WebView)layout.findViewById(R.id.wvdisplayimage);
wvdisplayimage.getSettings().setJavaScriptEnabled(true);
wvdisplayimage.setBackgroundColor(Color.parseColor("#f0ece9"));
wvdisplayimage.getSettings().setBuiltInZoomControls(true);
wvdisplayimage.loadDataWithBaseURL(null, "<style>img{display: inline;height: auto;max-width: 100%;}</style><img src='" + link + "'/>", "text/html", "UTF-8", null);
//wvdisplayimage.loadDataWithBaseURL(null, "<img src='" + link + "'/>", "text/html", "UTF-8", null);
//wvdisplayimage.loadData("<html><head><style type='text/css'>body{margin:auto auto;text-align:center;} img{width:100%25;} </style></head><body><img src=''" + link + "'/></body></html>" ,"text/html", "UTF-8");
/*String html = "<html><body><img src=\"" + link + "\" width=\"100%\" \"/></body></html>";
wvdisplayimage.loadData(html, "text/html", null);*/
d1.show();
btncanceldialog=(Button)layout.findViewById(R.id.btncancelredicon);
btncanceldialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
d1.dismiss();
}
});
}
showenlargeimagedialog.xml
<LinearLayout
android:id="@+id/llshowmoredialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal"
android:padding="2dp" >
<!-- Contents will go here.. -->
<WebView
android:id="@+id/wvdisplayimage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" >
</WebView>
</LinearLayout>
<Button
android:id="@+id/btncancelredicon"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:background="@drawable/round_button_background"
android:gravity="center_vertical|center_horizontal"
android:text="X"
android:textColor="#FFF"
android:textSize="12sp"
android:textStyle="bold" />
输出:
正如你可以看到web视图图像diaplaying 是在对话框的顶部 如何将图像移动在中心??
As you can see the image in webview is diaplaying at the top of the dialog.How to move the image in centre??
我在尝试SO许多其他的解决方案,但没有人似乎工作。
任何想法?
I have tried many other solutions in SO,but none of them seems working. Any Idea?
推荐答案
尝试使用 WRAP_CONTENT
的而不是 match_parent
您的WebView
布局
Try using wrap_content
instead match_parent
in your WebView
layout
这篇关于不能在一个对话的中心对齐网页视图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文