hun*_*dym 8 android colors android-listview layout-inflater
我使用LayoutInflater扩展视图.我的膨胀RelativeLayout的背景颜色在我的xml文件中设置.我在我的一个设备上遇到了一个奇怪的问题:有时(随机)背景颜色是我的colors.xml中的另一种(错误的)颜色.以前有人遇到过这个问题吗?
我有ListView
一个CursorAdapter
.我使用以下代码只使用一个静态项目(所以我认为这不是回收问题)来扩充列表项目:
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) ;
View v = vi.inflate(R.layout.bookmark_item, null) ;
//bindView(v, context, cursor) ;
Log.wtf("newView", "View color: " + Integer.toString(((ColorDrawable) (((RelativeLayout)v.findViewById(R.id.bookmark_row)).getBackground())).getColor())) ;
return v;
}
Run Code Online (Sandbox Code Playgroud)
我的layout/bookmark_item.xml
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/bookmark_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/app_menu_item_background"
tools:ignore="UselessParent" >
<TextView
android:id="@+id/bookmark_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
内部RelativeLayout的背景颜色设置为@color/app_menu_item_background
.这个颜色在我的R.java
:
public static final int app_menu_item_background=0x7f0a0036;
Run Code Online (Sandbox Code Playgroud)
我还有一个名为的颜色@color/app_menu_item_colored_background
,我在代码中的其他地方使用的颜色,它与我的书签列表和适配器没有任何共同之处.它还具有不同的资源ID R.java
:
public static final int app_menu_item_colored_background=0x7f0a0038;
Run Code Online (Sandbox Code Playgroud)
它们都是不同的颜色:
<color name="app_menu_item_background">#517409</color>
<color name="app_menu_item_colored_background">#f6efde</color>
Run Code Online (Sandbox Code Playgroud)
然后,在运行我的应用程序时,有时(并非总是),我的视图使用了错误的app_menu_item_colored_background
背景颜色.我记录了膨胀的视图颜色(见上面的代码),它甚至有时不同:
"newView" - "View color: -11439095"
"newView" - "View color: -593954"
Run Code Online (Sandbox Code Playgroud)
注意,第一种颜色是#517409
,第二种颜色是#f6efde
.
奇怪的是,我只能在一台设备上重现错误,三星Galaxy S3 mini,每10次尝试大约2-3次.
手动尝试
v.setBackgroundColor(getResources().getColor(R.color.app_menu_item_colored_background));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1758 次 |
最近记录: |