Scaling a Phonegap app for different Android screen sizes/densities?

前端 未结 4 922
误落风尘
误落风尘 2021-02-04 04:12

I have a Phonegap app designed to run on Android phones and tablets. The scale of text and images looks fine on a phone, but too small on a 7” tablet.

Is there a way to

4条回答
  •  梦毁少年i
    2021-02-04 04:58

    Just noticed I never answered this. The solution I used in the end was to use media queries to explicitly set font sizes and image assets based on the device size. Device testing showed this worked on all my target devices: iPhone, iPad, Android phones, Android 7" tablets, Android 10" tables. Hope it helps someone else.

    For example:

    /* Start with default styles for phone-sized devices */
        p,li{
            font-size: 0.9em;
        }
        h1{
            font-size: 1.2em;
        }
        button{
            width: 24px;
            height: 12px;
        }
        button.nav{
            background-image: url('img/phone/nav.png');
        }
    
    @media only screen and (min-device-width : 768px) { /* 7" tablets */
        p, li{
            font-size: 1.3em !important;
        }
        h1{
            font-size: 1.6em !important;
        }
        button{
              width: 32px;
              height: 16px;
        }
        button.nav{
            background-image: url('img/tablet7/nav.png');
        }
    }
    @media only screen and (min-device-width : 1024px) { /* 10" tablets and iPad */
        p, li{
            font-size: 1.5em !important;
        }
        h1{
            font-size: 1.8em !important;
        }
        button{
            width: 48px;
            height: 24px;
        }
        button.nav{
            background-image: url('img/tablet10/nav.png');
        }
    }
    

提交回复
热议问题