布局旋转和放;裁剪行为之前的Andr​​oid 4.3 [英] Layout Rotation & Clipping Behavior prior Android 4.3

查看:243
本文介绍了布局旋转和放;裁剪行为之前的Andr​​oid 4.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

旋转布局(如的FrameLayout)与图像视图里面的时候,在不同的Andr​​oid版本奇怪的行为。

Strange behavior when rotating a layout (e.g. a FrameLayout) with an image view inside, on different Android versions.

在下面这段XML布局看看:

Take a look at the following piece of XML layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000" >

    <FrameLayout
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:background="#ffffff"
        android:layout_gravity="center"
        android:rotation="15" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/bg" />

    </FrameLayout>

</FrameLayout>

下面将在Android 4.3和4.4,但奇怪的结果显示在Android 4.2,4.1,4.0.3良好的效果。

The following will display good results on Android 4.3 and 4.4, but strange result on Android 4.2, 4.1, 4.0.3.

在Android 4.2(坏的结果)

On Android 4.2 (bad result)

在Android 4.3(好结果)

on Android 4.3 (good result)

任何人知道为什么出现这种情况到Android 4.3之前,如何解决?

Anyone knows why this happens prior to Android 4.3 and how to fix it ?

谢谢!

推荐答案

好像我无法重现的问题,因为我没有启用使用GPU的主机。

Seems like I couldn't reproduce the problem since I didn't enable "use GPU host".

总之,这里的克服这种方式,即使该功能启用它:

Anyway, here's a way to overcome this, even if this feature its enabled :

的android:layerType =软件作为ImageView的

set android:layerType="software" for the imageView .

我希望你不需要动画,因为这属性会影响性能。

I hope you don't need to animate, since this attribute affects the performance.

为了让它更好地工作(至少在新的Andr​​oid版本),我建议做,这将是软件为达问题的版本(含),并从它上面的硬件的资源。

In order to make it work better (at least for newer Android versions), I suggest making a resource that will be "software" for up to the problematic version (including), and "hardware" from above it.

我试过处理它其他的方法,但他们并不能很好地工作。

I've tried other methods of handling it, but they don't work well.

您可能能够在layerType在运行时复位,所以你会得到它毕竟运作良好。
对我来说,它的工作。

You might be able to reset the layerType at runtime, so you'll get it working well after all. For me it worked.

只要致电:

  @Override
  protected void onCreate(final Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.imageView1).setLayerType(View.LAYER_TYPE_HARDWARE,null);
    }

这篇关于布局旋转和放;裁剪行为之前的Andr​​oid 4.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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