简体   繁体   English

Android中的媒体查询

[英]Media Queries in Android

I would like to use different css files for different android phone device widths. 我想针对不同的Android手机设备宽度使用不同的CSS文件。 We have one Samsung Galaxy Mini (device-width: 320px) and one Samsung Galaxy Note 4 (device-width: 360px) for testing. 我们有一台Samsung Galaxy Mini(设备宽度:320像素)和一台Samsung Galaxy Note 4(设备宽度:360像素)进行测试。 When we use the following code, no css file is loaded: 当我们使用以下代码时,不会加载任何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)" /> 

What could be the solution? 有什么解决方案?

I found the solution, but now we have another problem: My scrollView's android:layout_height was set to WRAP_CONTENT . 我找到了解决方案,但是现在我们遇到了另一个问题:我的scrollView的android:layout_height设置为WRAP_CONTENT According to the following doc , it should be set to MATCH_PARENT . 根据以下文档 ,应将其设置为MATCH_PARENT
I quote from there: 我从那里引用:

"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." “建议将WebView布局高度设置为固定值或MATCH_PARENT而不是使用WRAP_CONTENT。当使用MATCH_PARENT作为高度时,任何WebView的父级都不应该使用WRAP_CONTENT布局高度,因为这可能导致视图尺寸错误。 ”

I also changed the media queries as follows: 我还更改了媒体查询,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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