0

すべての画面密度に共通の hdpi フォルダーを使用することは可能ですか? 私はかなり多くのイメージを持っています。drawable-hdpi、drawable-ldpi、drawable-xhdpi などのフォルダーに特定のコピーを作成すると、膨大なデータ (背景、ビットマップ) が必要になります。

すべてのデバイスに対して描画可能なフォルダーを 1 つだけ設定し、特定のデバイスに応じてプログラムで再スケーリングすることは可能ですか?

画面の表示サイズを取得するには、次のコードを考えます。

Display display = getWindowManager().getDefaultDisplay();
width = display.getWidth();
height = display.getHeight();

次に、次のようなデバイスの表示密度を取得します。

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
density = metrics.density; // 1 - 1,5 - 2 .....

密度を使用してイメージビューのサイズを再計算します。

ImageView logo = (ImageView)findViewById(R.id.logo);
LinearLayout.LayoutParams logo1 = (LinearLayout.LayoutParams) logo.getLayoutParams();
logo1.width = (int)(logo.getWidth()*density);
logo1.height = (int)(logo.getHeight()*density);
logo1.leftMargin=(int)(logo1.leftMargin*density);   // for margin
logo1.topMargin=(int)(logo1.topMargin*density);   // for margin
logo1.rightMargin=(int)(logo1.rightMargin*density);   // for margin
logo1.bottomMargin=(int)(logo1.bottomMargin*density);   // for margin

私の主な問題は、すべてのデバイスでグラフィックのすべての比率を同じにする必要があることです。これは、画面サイズに合わせて imageViews を再計算する必要があることを意味します。

これは、密度に依存しない画面を取得する正しい方法ですか? hdpiフォルダーにのみファイルが含まれている場合、Androidは他のデバイスでどのように機能しますか. このフォルダからファイルを取得しますか? 1 つの共通のドローアブル フォルダーをすべての密度に設定できますか?

4

1 に答える 1

2

I would strongly (strongly) advise against doing this. However, if you want the system to rescale your image assets, design them for mdpi (the baseline density) and put them in drawable/.

That said, you need at least mdpi and hdpi to get reasonable scaling (since hdpi is 1.5x mdpi, scaling algorithms produce worse results than for the other conversions from mdpi).

Make sure you've read and understood Providing Resources and Supporting Multiple Screens before you start dealing with resources.

P.S. The layout solution is wrong for a few reasons (e.g., setting margins instead of size) but it's also the completely wrong thing to do. Don't do it!

于 2013-04-19T12:00:14.783 に答える