简体   繁体   中英

Adding level in level-list via the Java code

I am developing an app with 360 degree view of a certain item. I have the following level list for the same:

 <?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:maxLevel="0" android:drawable="@drawable/a1" />
  <item android:maxLevel="1" android:drawable="@drawable/a18" />
  <item android:maxLevel="2" android:drawable="@drawable/a17" />
  <item android:maxLevel="3" android:drawable="@drawable/a16" />
  <item android:maxLevel="4" android:drawable="@drawable/a15" />
  <item android:maxLevel="5" android:drawable="@drawable/a14" />
  <item android:maxLevel="6" android:drawable="@drawable/a13" />
  <item android:maxLevel="7" android:drawable="@drawable/a12" />
  <item android:maxLevel="8" android:drawable="@drawable/a11" />
  <item android:maxLevel="9" android:drawable="@drawable/a10" />
  <item android:maxLevel="10" android:drawable="@drawable/a9" />
  <item android:maxLevel="11" android:drawable="@drawable/a8" />
  <item android:maxLevel="12" android:drawable="@drawable/a7" />
  <item android:maxLevel="13" android:drawable="@drawable/a6" />
  <item android:maxLevel="14" android:drawable="@drawable/a5" />  
  <item android:maxLevel="15" android:drawable="@drawable/a4" />
  <item android:maxLevel="16" android:drawable="@drawable/a3" />
  <item android:maxLevel="17" android:drawable="@drawable/a2" />
</level-list>

I need to add images to the levels via the java code. I will be downloading the images, and they will be stored in the sd card.

Is there any way to achieve this?

According to the Official Documentation of Android , yes you can by using addLevel (int low, int high, Drawable drawable)

Sample

LevelListDrawable lld = new LevelListDrawable ();
lld.addLevel (0, 1, your_drawable);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM