HTMLコードがいくつかあり、それをWebViewにロードします。ボタンの幅をパーセントで設定する必要があります(画面の解像度に依存しないようにするため)。
ボタンの幅をパーセントで設定すると、エラーが発生しますがpage cannot be loaded
、ピクセルで設定しても問題ありません。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type='text/css'>
body{ position: relative; }
button { width: 50%; display: block; position: relative; }
</style>
</head>
<body style='text-align:justify;color:white;'>
Some text
<br/>
<button>Boo!</button>
</body>
</html>
何かご意見は?
編集:
解決策は、@Zak のアドバイスに基づいて見つかりました。つまり、ページが読み込まれた後にjs関数を呼び出し、画面の幅を取得して要素に設定することです。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language='javascript'> function SetWidth(){ d = document.getElementById('but'); d.style.width=screen.width/2; } </script>
<style type='text/css'> body{ position: relative; } button { display: block; position: relative; } </style>
</head>
<body style='text-align:justify;color:white;'>
Text<br/>
<button id='but' >Scary!</button>
<script> window.onload=SetWidth; </script>
</body>
</html>