2013-01-10 50 views
1

我加载在WebView中一些HTML内容,但它总是在我的WebView的左上角到来。如何在中心设置WebView内容?

我曾尝试使用样式表也,在我加入中心的相关产品关键词,但其在中心不来的样式表。样式表中的其他标签工作正常。

如何设置的WebView内容垂直和水平中心?

我的HTML代码

<html><head> <style type=\"text/css\"> @font-face { font-family: MyCustomFont; src:url(\"file:///android_asset/fonts/MyriadPro-Regular.otf\") } body { font-family: MyCustomFont; font-size:14; text-align: center;vertical-align:middle;line-height: normal;} </style> </head><body> Hello World </body></html> 
+0

任何链接到该网站的问题,以及相关的代码?作为第一步,您可以尝试使用android:gravity =“center”作为 – ninetwozero

+0

。 这可能(可能不会)帮助。这就是为什么不把答案。 – akkilis

回答

3

试试这个:

<html> 
<head> 
    <style type="text/css"> 
@font-face { font-family: MyCustomFont; 
src:url("~/android_asset/fonts/MyriadPro-Regular.otf") } 
#text{ font-family: MyCustomFont; 
font-size:14; 
text-align: center; 
margin:350px; 
line-height: normal; 
color:blue; 
height:20px; 
width:100px; 
margin:auto; 
background-color:red; 
} 
</style> 
</head> 
<body> 
<p id="text"> Hello World</p> 
</body> 
</html> 

而且我觉得你的地址源字体是错误的!

+0

我已经通过使用样式表修改了代码中的一些修改。感谢帮助。 – Mac

-2
<WebView android:id="@+id/webview1" 
    android:layout_gravity="center" 
    android:scaleType="centerInside" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:adjustViewBounds="true"> 

它可以帮助你。

+3

它不会实际上,layout_gravity适用于整个网页视图而非网页视图的内容。 您提到的其他标签与正在讨论的问题无关。 – akkilis