如何制作适用于移动设备和平板电脑的自适应Android应用程序? [英] How to make responsive Android application which is used in mobile and also in tablet?

查看:108
本文介绍了如何制作适用于移动设备和平板电脑的自适应Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Android应用程序.

I have created one Android application.

当我在Mobile Phone中运行我的应用程序时,效果很好,但是当我在Tablet中运行时,应用程序的布局已更改.

When I run my application in Mobile Phone it works very well, but when I run in Tablet the layout of application is changed.

那么,如何制作在MobileTablet中使用的响应式Android应用程序?

So, how to make responsive Android application which is used in Mobile and also in Tablet?

推荐答案

在Android上,我们可以使用 Android 3.2引入的 屏幕尺寸选择器 ,以定义要使用的布局. 有关更多详细信息,请参见 http://android -developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html .以下代码段已从同一链接中提取:

On Android we can use screen size selector, introduced from Android 3.2, to define which layout to use. More details available at http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html. Following code snippet has been extracted from the same link :

public class MyActivity extends Activity 
{
    @Override protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate();
        Configuration config = getResources().getConfiguration();
        if (config.smallestScreenWidthDp >= 600) 
        {
            setContentView(R.layout.main_activity_tablet);
        } 
        else 
        {
            setContentView(R.layout.main_activity);
        }
    }
}

关于大小配置的另一个很好的参考是保留分隔符.有关详细信息,请参见: http://www.vanteon.com/downloads/Scaling_Android_Apps_White_Paper.pdf

Another good reference for size configuration is keeping separator. This is explain in details at : http://www.vanteon.com/downloads/Scaling_Android_Apps_White_Paper.pdf

这篇关于如何制作适用于移动设备和平板电脑的自适应Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆