OrientationEventListener(片与移动)90度的差异 [英] OrientationEventListener (Tablet vs Mobile) 90 degree difference

查看:559
本文介绍了OrientationEventListener(片与移动)90度的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用im OrientationEventListener检测方向,但我有一个问题,即药片的景观和手机都默认画像。这意味着,对于OrientationEventListener在平板电脑上的画像返回90值,但0在手机上的肖像。

我使用的活动有摄像头,所以我不能取向之间改变,所以我使用的价值取向,重新定位了几个要素需要在屏幕上。

是否有可能检测该设备是否片剂,这样我可以相应地调整的值。即怎样制定出isTablet的价值?

 如果(isTablet)
            {
                定向+ = -90;
                如果(方向℃下)//检查是否太过分了回来,保持0-360之间的结果
                {
                    定向+ = 360;
                }
            }


解决方案

既然你提到你不能取向之间改变,你将不得不使用该设备的属性,以弄清楚它是否是平板电脑。

看看这个参考

您可以使用 android.os.Build.DEVICE android.os.Build.MODEL android.os.Build.PRODUCT 来获取设备的身份,从这个知识,你可以使用<一个href=\"http://www.glbenchmark.com/phonedetails.jsp?benchmark=glpro21&D=Amazon+Kindle+Fire&testgroup=system\"相对=nofollow>这个引用找到他们的价值观,并确定是什么设备类型。

但是,使用这种方法,你必须每一个新的平板电脑发布时间更新软件。 (我用<一个href=\"http://stackoverflow.com/questions/3213205/how-to-detect-system-information-like-os-or-device-type\">this问题,作为答案的该部分)的引用。

交替是我发现这里,从答案报价:

 公共布尔isTablet(上下文的背景下){
    布尔XLARGE =((context.getResources()getConfiguration()屏幕布置和放大器; Configuration.SCREENLAYOUT_SIZE_MASK)== 4);
    布尔大=((context.getResources()getConfiguration()屏幕布置和放大器; Configuration.SCREENLAYOUT_SIZE_MASK)== Configuration.SCREENLAYOUT_SIZE_LARGE);
    回报(XLARGE ||大);
}


  

大XLARGE的屏幕尺寸为基于制造商决定
  从眼睛的距离它们是在(因此的想法中使用
  平板电脑)。


希望这有助于!

Im using OrientationEventListener to detect the orientation, but I have a problem in that the tablets are landscape and phones are portrait by default. This means that OrientationEventListener returns a value of 90 for portrait on tablets, but 0 for portrait on mobiles.

The activity I am using has the camera so I cannot change between orientations, thus I use the value of Orientation to reposition a couple of elements on the screen as needed.

Is it possible to detect if the device is a tablet, so that I can adjust the value accordingly. i.e. How do I work out the value of isTablet?

            if(isTablet)
            {
                orientation += -90;
                if(orientation < 0) //Check if we have gone too far back, keep the result between 0-360
                {
                    orientation += 360;
                }   
            }

解决方案

Since you have mentioned that you cannot change between orientations, you'll have to use the device's properties to figure out if it is a tablet.

Take a look at this reference.

You can use android.os.Build.DEVICE, android.os.Build.MODEL and android.os.Build.PRODUCT to get the identity of the device, and from this knowledge, you can use this reference to find their values and determine what is the device type.

But using this method, you'd have to update the software each time a new tablet is released. (I have used this question as a reference for this part of the answer).

Alternate is what I have found here, quoting from the answer:

public boolean isTablet(Context context) {
    boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
    boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
    return (xlarge || large);
}

LARGE and XLARGE Screen Sizes are determined by the manufacturer based on the distance from the eye they are to be used at (thus the idea of a tablet).

Hope this helps!

这篇关于OrientationEventListener(片与移动)90度的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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