私はここや他の場所を見回しましたが、この問題の解決策を見つけることができないようです。これは私の最初のAndroidアプリケーションですが、私はJavaに精通しています。
私は3つのImageButtonを表示しています(一方が他方の上にあります)。これは、任意の画面に合わせてサイズを変更する必要があります(つまり、7-10インチのタブレットから4インチの電話)。私はこの論理を理解していますが、私が遭遇している問題は、7インチ以上のデバイスの画像の品質がひどいことです。これが私のxmlのコードです:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLayout" >
<ImageButton
android:id="@+id/btn_god"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@null"
android:src="@drawable/godtext" />
<ImageButton
android:id="@+id/btn_growth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:background="@null"
android:src="@drawable/growthtext" />
<ImageButton
android:id="@+id/btn_service"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="@null"
android:src="@drawable/servicetext" />
</RelativeLayout>
そして、これが私の活動の関連部分です:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int version = VERSION.SDK_INT;
int height = 0;
int width = 0;
if (version < 13){
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
height = displaymetrics.heightPixels;
width = displaymetrics.widthPixels;
} else {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
width = size.x;
height = size.y;
}
/**
* Creating all buttons instances
* */
// Dashboard God button
ImageButton btn_god = (ImageButton) findViewById(R.id.btn_god);
btn_god.setAdjustViewBounds(true);
ViewGroup.LayoutParams params = btn_god.getLayoutParams();
params.height = height/4;
params.width = params.height;
btn_god.setLayoutParams(params);
// Dashboard Growth button
ImageButton btn_growth = (ImageButton) findViewById(R.id.btn_growth);
btn_growth.setAdjustViewBounds(true);
params = btn_growth.getLayoutParams();
params.height = height/4;
params.width = params.height;
btn_growth.setLayoutParams(params);
btn_growth.setImageResource(R.drawable.growthtext);
// Dashboard Service button
ImageButton btn_service = (ImageButton) findViewById(R.id.btn_service);
btn_service.setAdjustViewBounds(true);
params = btn_service.getLayoutParams();
params.height = height/4;
params.width = params.height;
btn_service.setLayoutParams(params);
私がやりたいのは、高解像度の画像を撮り、それを小さい画面に合うように縮小することです。ただし、低解像度の画像を撮影し、大画面用に拡大しているようです。誰かが同様の問題に遭遇しましたか?どのようにそれを解決しましたか?どんな回答にも感謝します!