2

我在包含片段的线性布局上运行简单的 setRotation 时遇到问题。在 Galaxy S3 上运行并在开发人员选项中勾选禁用硬件覆盖会使一切工作非常顺利,如果没有它,它会导致在横向显示时只有部分视图以随意的补丁类型显示。

我旋转视图并调整其布局参数的原因是,即使在屏幕旋转期间,我也需要在用户选择的项目中显示一个列表。

视图显示在相机表面上方。

视图的xml布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/occasionsOptionsLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:gravity="top"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical" >

    <TextView
        android:id="@+id/whatOccasionTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.7"
        android:gravity="left"
        android:padding="8dp"
        android:text="@string/whatstheoccasion"
        android:textColor="@color/Black"
        android:textSize="@dimen/textMedium" />

    <ImageView
        android:id="@+id/occasionTitleImage"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_margin="2dp"
        android:layout_weight="0.3"
        android:padding="2dp"
        android:src="@drawable/mood" />
</LinearLayout>

<ScrollView
    android:id="@+id/occasionscrollView"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1" >

        <fragment
            android:id="@+id/occasion_fragment"
            android:name="com.myapp.record.Occasions"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
             />
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/occasionaOptionsClose"
    android:layout_width="fill_parent"
    android:layout_height="55dp"
    android:layout_gravity="center_vertical"
    android:gravity="center_vertical"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/occasionsOptionsCloseAction"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:src="@drawable/close" />
</LinearLayout>

</LinearLayout>

以及旋转视图的调用:

 occasionsIncluder = (LinearLayout) findViewById(R.id.occasionIncluder);
occasionsIncluder.setRotation(rotateToValue);

rotateToValue 是对屏幕方向值的简单调用,以度为单位。

我的问题是为什么禁用硬件覆盖会导致它实际上更好地工作,我认为这个选项是为了让事情运行得更顺畅?

4

2 回答 2

2

问:为什么禁用硬件覆盖会使其实际上更好地工作?

答:我想指导您查看有关硬件加速的官方 android 文档。它说:

Because of the increased resources required to enable hardware acceleration, your app will consume more RAM.

If your application uses only standard views and Drawables, turning it on globally should not cause any adverse drawing effects. However, because hardware acceleration is not supported for all of the 2D drawing operations, turning it on might affect some of your applications that use custom views or drawing calls. Problems usually manifest themselves as invisible elements, exceptions, or错误渲染的像素

To remedy this, Android gives you the option to enable or disable hardware acceleration at the following levels:

  • 应用
  • 活动
  • 窗户
  • 看法

希望这可以帮助您了解原因。有关更多信息,您可以阅读链接。

于 2013-05-27T23:27:16.437 回答
0

setWillNotDraw() 是罪魁祸首

于 2013-06-05T05:14:25.907 回答