用背景图像填充android并在横向和纵向视图中维护它

时间:2011-08-25 05:17:02

标签: android cordova

目标: - 在我的应用程序中设置背景图像,以纵向和横向模式填充设备

使用的工具:带有eclipse的Phonehgap

遇到的问题: -

  • 1)我的图像在纵向模式下根据设备宽度拟合但是 如果高度只占设备的50%,则情况不一样
  • 2)在android模拟器中切换到横向模式图像
    闪烁并在2秒内消失

我在谷歌搜索后添加的代码: -

1)在main.xml

  <WebView android:id="@+id/appView"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
      />

2)在activity.java中

import android.util.Log;
import android.view.Display;
import android.webkit.WebSettings.RenderPriority;
import android.view.WindowManager;
import android.content.Context;

3)在索引页面

  <meta name="viewport" content="target-densitydpi=device-dpi"  />
or 
<meta name="viewport" content="user-scalable=no, width=device-width" />
<link rel="stylesheet" href="homepage.css" type="text/css" media="only screen and (max-width: 480px)"/>

注意: - 其余代码是简单的html和css以及我们必须修改的所有手机间隙

赞成我想要: - 在告诉代码的同时请告诉我在哪里也包括,因为我是eclipse和phonegap的新手

提前

thanx

1 个答案:

答案 0 :(得分:4)

使用jquery mobile并且不使用作为平台的工具进行任何更改(例如eclipse for android) 并将图像填充到设备大小是简单的css

{
 background-image:url('Images/indeximage.jpg');
 background-size: 100% 100%;
 background-repeat:no-repeat;
 background-position:100% 100%;
 top: 0px;
 left: 0px;

}