端末に最適な壁紙サイズを取得する |
ここでは端末に最適な壁紙サイズを取得する方法を確認していきます。
画面のサイズは端末の種類によって異なります。 最適な壁紙サイズというのは、端末の最低画像サイズが推奨されています。 この、最低画像サイズは、「 WallpaperManager 」クラスから取得することができます。 ・最適な幅 → WallpaperManager.getDesiredMinimumWidth() ・最適な高さ → WallpaperManager.getDesiredMinimumHeight() それぞれ幅と高さをピクセル単位で取得することが可能です。 WallpaperActivity.java package goodroid.sample.wallpaper; import android.app.Activity; import android.app.WallpaperManager; import android.os.Bundle; import android.widget.TextView; public class WallpaperActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); WallpaperManager wm = WallpaperManager.getInstance(this); TextView text1 = (TextView)findViewById(R.id.text1); TextView text2 = (TextView)findViewById(R.id.text2); // 最適な幅を取得 int width = wm.getDesiredMinimumWidth(); // 最適な高さを取得 int height = wm.getDesiredMinimumHeight(); text1.setText("最適な幅:" + String.valueOf(width) + "px"); text2.setText("最適な高さ:" + String.valueOf(height) + "px"); } } main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/text2" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> 実行結果 ![]() |
4284 views | コメント:0 | 2012-06-23 |
コメント
|
|
まだこの記事にコメントはありません |