我想为不同的 android 手机设备宽度使用不同的 css 文件。 我们有一台 Samsung Galaxy Mini (device-width: 320px) 和一台 Samsung Galaxy Note 4 (device-width: 360px) 进行测试。当我们使用以下代码时,没有加载任何 css 文件:
<link href="css/iss_320_530_01_00.css" rel="stylesheet" type="text/css" media="only screen and (device-width: 320px)" />
<link href="css/iss_360_640_01_00.css" rel="stylesheet" type="text/css" media="only screen and (device-width: 360px)" />
可能的解决方案是什么?
最佳答案
我找到了解决方案,但现在我们遇到了另一个问题:我的 scrollView 的 android:layout_height
被设置为 WRAP_CONTENT
。根据following doc ,它应该设置为 MATCH_PARENT
。
我从那里引用:
"It is recommended to set the WebView layout height to a fixed value or to MATCH_PARENT instead of using WRAP_CONTENT. When using MATCH_PARENT for the height none of the WebView's parents should use a WRAP_CONTENT layout height since that could result in incorrect sizing of the views."
我还更改了媒体查询如下:
<link href="css/iss_320_530_01_00.css" rel="stylesheet" type="text/css" media="screen and device-width: 320px" />
<link href="css/iss_360_640_01_00.css" rel="stylesheet" type="text/css" media="screen and device-width: 360px" /> Now, css files are loaded for Samsung Galaxy S3 Mini, but not for Samsung Note 4.
关于android - Android 中的媒体查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35291886/