Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android ImageView with level-list do not work

start_background.xml

<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:drawable="@color/grey"
    android:maxLevel="1"
    />
<item
    android:drawable="@color/grey"
    android:maxLevel="2"
    />
<item
    android:drawable="@color/grey"
    android:maxLevel="3"
    />

</level-list>

start_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"

android:id="@+id/page"
>
<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/start_background"
    android:id="@+id/start"
    />
</LinearLayout>

Java Code

ImageView image= (ImageView)findViewById(R.id.start);
LevelListDrawable background=(LevelListDrawable)image.getBackground();
background.setLevel(3);

but it can not change the background, I have try to change android:background to android:src, it didn't work also.

logcat:

2690-2705/com.jifa.runandcatch2 W/EGL_emulation﹕     eglSurfaceAttrib not implemented
2690-2705/com.jifa.runandcatch2 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xae0e1de0, error=EGL_SUCCESS

how to solve it, thanks.

like image 229
jifa Avatar asked Mar 05 '15 01:03

jifa


Video Answer


1 Answers

Use:

image.setImageLevel(3);

instead than:

LevelListDrawable background=(LevelListDrawable)image.getBackground(); background.setLevel(3);

like image 88
zzworks Avatar answered Sep 27 '22 18:09

zzworks