Mac
Mac

Reputation: 1163

How to set WebView Content in Center?

I am loading some HTML content in WebView but its always coming in the top left corner of my WebView.

I have tried to use stylesheet also, in stylesheet I have added center related tages but its not coming in center. others tags in stylesheet works fine.

How to set content in WebView vertically and horizontally center ?

my HTML Code

<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>

Upvotes: 1

Views: 8694

Answers (2)

Hamid Talebi
Hamid Talebi

Reputation: 1318

try this:

<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>  

And I think that your address source font is mistake!

Upvotes: 3

Nirav Tukadiya
Nirav Tukadiya

Reputation: 3417

<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">

it might help you.

Upvotes: -2

Related Questions