Android的方向变化导致东西消失方向、东西、Android

2023-09-07 11:39:00 作者:情↘已逝去つ

下面是我在SimpleCursorAdapter行模板布局。

Below is my layout for the row template in a SimpleCursorAdapter.

ID为ImageView的 next_arrow 永久消失的方向上的变化(回到原来的方向不会使它重新出现)。与@绘制/图标(标准 sym_def_app_icon 复印件),它工作正常,如果我更换@绘制/箭头。有关所有可绘制的简单的PNG文件

The ImageView with id next_arrow disappears permanently on orientation change (going back to original orientation doesn't make it re-appear). If I replace @drawable/arrow with @drawable/icon (copy of the standard sym_def_app_icon) it works fine. All the drawables in question are simple references to PNG files.

我想这可能是某种联系的图标是不同尺寸的,但我调整@绘制/图标的确切尺寸相同的箭头,它仍然能正常工作,而箭头没有。

I thought it might be somehow related to the icons being of different dimensions, but I resized @drawable/icon to be the exact same dimensions as the arrow and it still worked fine while the arrow didn't.

更新

好吧它会变得怪异。我改名为 arrow.png 为 something_not_called_arrow.png 并...它的作品。这是怎么回事?

Okay it gets even weirder. I renamed the arrow.png to something_not_called_arrow.png and... it works. What is going on?

这不是我第一次看到这种情况发生。今天早些时候,我有另外的绘制PNG的显示在Eclipse图形布局视图罚款,但不肯露面在所有的仿真器或设备上,直到我重命名的文件。我试图清理并刷新该项目,并重新启动Eclipse的。

This isn't the first time I've seen this happen. Earlier today I had another drawable PNG that showed fine in the Eclipse Graphical Layout view, but refused to show up at all in the Emulator or on a device until I renamed the file. I tried cleaning and refreshing the project, and restarting Eclipse.

另一个更新

刚曾在不同的情况再次发生这种情况。在活动的onCreate()我叫findViewById()的几个资源进行配置,一切正常,第一次加载的罚款。当的onCreate()被调用由于改变方向时findViewById()返回null所有这些资源。这是郁闷,答案涉及的android:configChanges =keyboardHidden |方向根本不是真正的解决方案,他们只是掩盖问题

Just had this happen again in a different situation. In Activity onCreate() I call findViewById() on a few resources to configure them, everything works fine on first load. When onCreate() is called due to an orientation change, findViewById() returns null for all these resources. This is maddening, and the answers that involve android:configChanges="keyboardHidden|orientation" aren't real solutions at all, they are just masking the problem.

在这种情况下,我从 share.xml 重命名的布局XML对于该活动的 share_activity_layout.xml 固定了。我开始认为这是在一般的R档生成和资源ID管理某种错误的。

In this case I "fixed" it by renaming the layout xml for the activity from share.xml to share_activity_layout.xml. I'm starting to think there is some kind of bug in the R file generation and resource ID management in general.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="90dp"
              android:background="@drawable/product_list_divider"
              android:paddingTop="10dp">

    <ImageView android:src="@drawable/ninja_20_65"
               android:id="@+id/category_icon" 
               android:layout_marginLeft="20dp"
               android:layout_marginRight="20dp"
               android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="3dp"/>

    <LinearLayout android:orientation="vertical"
                  android:layout_weight="5"
                  android:layout_width="0dp"
                  android:layout_height="wrap_content">

        <TextView android:id="@+id/category_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:text="Name" 
            style="@style/CategoryHeading" android:layout_marginTop="5dp"/>
        <TextView android:id="@+id/category_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="Description"
            style="@style/CategoryDescription"/>
    </LinearLayout>

    <ImageView android:src="@drawable/arrow"
               android:layout_weight="1"
               android:layout_width="0dp"
               android:layout_marginRight="10dp"
               android:layout_height="wrap_content" android:layout_marginTop="20dp" android:id="@+id/next_arrow"/>

</LinearLayout>

我采用了Android 2.1。

I'm using Android 2.1.

推荐答案

我改名 arrow.png something_not_called_arrow.png 和它的作品。

I renamed the arrow.png to something_not_called_arrow.png and it works.

有一个后续的类似问题通过重命名布局XML从share.xml的活动share_activity_layout.xml我固定。

There was a subsequent similar issue which I "fixed" by renaming the layout xml for the activity from share.xml to share_activity_layout.xml.

我觉得这是在一般的R档生成和资源ID管理的错误。

I think there is a bug in the R file generation and resource ID management in general.

 
精彩推荐
图片推荐