我想将 webview 中的图片与对话框的中心对齐。
相关代码:
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" />
输出:
正如您所见,webview中的图像是在对话框顶部显示 。如何在中心移动图像?
我在SO中尝试了很多其他解决方案,但它们似乎都没有用。 有什么想法吗?
答案 0 :(得分:1)
尝试在wrap_content
布局
match_parent
代替WebView
答案 1 :(得分:0)
传递此样式android.R.style.Theme_Black_NoTitleBar_Fullscreen
Dialog构造函数:
final Dialog d1 = new Dialog(ThirtyArticleDetail.this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);