简体   繁体   中英

android 4.4 - webview don't accept css width 100%

I has a problem with the new implementation of webview for android 4.4+.

My HTML code:

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script src="http://s.videos.globo.com/p2/j/api.min.js" type="text/javascript"></script>
    <style type="text/css" media="all">
        #player-wrapper, #image-wrapper {
            width: 100% !important;
            height: 100% !important;
            position: absolute;
            left: 0;
            top: 0;
            z-index: 1;
        }
        #image-wrapper {
            z-index: 999;
            background-color: white;
        }
    </style>
</head>
<body>
    <div id="player-wrapper"></div>
    <img id="image-wrapper">

    <script type="text/javascript">
        var element = document.getElementById('player-wrapper');
        var image = document.getElementById('image-wrapper');

        var player = new WM.Player({
                        autoPlay: true,
                        width: 640,
                        height: 360
                    });

        player.attachTo(element);

        image.onclick = function() {
            player.playVideo();
            image.style.visibility = 'hidden';
        };
    </script>
</body>

But the rule width: 100% is not working, the # player-wrapper is getting bigger than the webview. Strange that only the #player is being affected, #image are right.

Can anyone help me with this?

The problem lies in the WM.player constructor, which sets the width of the player to 640px, which is probably bigger than your viewport. There is no parameter for max-width in the WM.Player constructor, so you'll have to use a meta tag. Trying adding <meta name="viewport" content="width=640px"> in the head section of your HTML so that the viewport is sized to fit the 640px width set in the WM.Player constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM