WEB开发网
开发学院手机开发Android 开发 Live Wallpaper动态壁纸开发 阅读

Live Wallpaper动态壁纸开发

 2011-07-01 20:50:24 来源:本站整理   
核心提示:}mColorRectangles[21] = new Rect(0, mColorRectangles[20].bottom, mColorRectangles[7].right, mRectFrame.bottom); }}private void CreateEbu(){ if(mHorizontal) {int

  }
  mColorRectangles[21] = new Rect(0, mColorRectangles[20].bottom, mColorRectangles[7].right, mRectFrame.bottom); 
  
  }
 }

 private void CreateEbu()
 {
  if(mHorizontal)
  {
  int narrowColumnWidth = mRectFrame.right / 8;

mColorRectangles[0] = new Rect(0, 0, narrowColumnWidth, mRectFrame.bottom); 
  for (int i = 1; i < 8; i++)
  {
   mColorRectangles[i] = new Rect(mColorRectangles[i - 1].right, 0, mColorRectangles[i - 1].right + narrowColumnWidth, mRectFrame.bottom); 
  }

  }
  else
  {
  int narrowColumnWidth = mRectFrame.bottom / 8;


  mColorRectangles[0] = new Rect(0, 0, mRectFrame.right, narrowColumnWidth);
  for (int i = 1; i < 8; i++)
  {
   mColorRectangles[i] = new Rect(0, mColorRectangles[i - 1].bottom, mRectFrame.right, narrowColumnWidth + mColorRectangles[i - 1].bottom);
  }
  }
 }
 }
}

 这里需要注意的是在androidmanifest.xml文件中加入

<service android:name=".LiveWallpaper" android:label="@string/app_name"  android:icon="@drawable/icon">
  <intent-filter>
    <action android:name="android.service.wallpaper.WallpaperService" />
   </intent-filter>
   <meta-data android:name="android.service.wallpaper" android:resource="@xml/livewallpaper" />
</service>

4.   新建类LiveWallpaperSettings从 PreferenceActivity 继承实现我们的设置界面,代码如下

  public class LiveWallpaperSettings extends PreferenceActivity
 implements SharedPreferences.OnSharedPreferenceChangeListener
{
 @Override
 protected void onCreate(Bundle icicle)
 {
 super.onCreate(icicle);
 getPreferenceManager().setSharedPreferencesName(LiveWallpaper.SHARED_PREFS_NAME);
 addPreferencesFromResource(R.xml.livewallpaper_settings);
 getPreferenceManager().getSharedPreferences()
  .registerOnSharedPreferenceChangeListener(this);
 }
 
 @Override
 protected void onResume()
 {
 super.onResume();
 }

 @Override
 protected void onDestroy()
 {
 getPreferenceManager().getSharedPreferences()
  .unregisterOnSharedPreferenceChangeListener(this);
 super.onDestroy();
 }

 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
  String key)
 {
 }
}

同时仍然在androidmanifest.xml中加入 下面的代码。

<activity android:label="@string/livewallpaper_settings"
  android:name=".LiveWallpaperSettings"
  android:theme="@android:style/Theme.Light.WallpaperSettings"
  android:exported="true"
  android:icon="@drawable/icon">
 </activity>

5. 由于Android动态壁纸是2.1 API Level为7才加入的,所以设置好minSDK以及需要设备支持动态壁纸,我们在androidmanifest.xml中加入

 <uses-sdk android:minSdkVersion="7" />
 <uses-feature android:name="android.software.live_wallpaper" />

 6. 对于文中ListPreference用到的数组,及代码中涉及的颜色数组,我们在/res/values/ 文件夹中创建一个名为testpatterns.xml 的文件,内容为

  <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
 <string-array name="livewallpaper_testpattern_names">
 <item>"Color Bars 16x9"</item>
 <item>"Color Bars 4x3"</item>
 <item>"EBU Color Bars"</item>
 </string-array>

 <string-array name="livewallpaper_testpattern_prefix">
 <item>"smpte"</item>
 <item>"bars"</item>
 <item>"ebu"</item>

上一页  2 3 4 5 6 7 8  下一页

Tags:Live Wallpaper 动态

编辑录入:coldstar [复制链接] [打 印]
赞助商链接