使用此代碼即可。縮放ImageView。 MultiScreen
Resources r = MainActivity.ct.getResources();
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200,r.getDisplayMetrics());
View inflatedLayout = getLayoutInflater().inflate(R.layout.list_row_layout, null, false);
inflatedLayout.findViewById(R.id.thumbImage).getLayoutParams().width *= px/540;
inflatedLayout.findViewById(R.id.thumbImage).getLayoutParams().height *= px/960;
但我有應用程序崩潰。如何改變我的imageView佈局的寬度和高度?謝謝。
請分享完整的代碼或logcat的 –
您正在編寫這些代碼withing MainActivitiy桑尼是U使用MainActivity.ct.getResources()原因,請檢查Resource的值r = MainActivity.ct.getResources();在調用這個之後,如果它返回的null valur到r app會崩潰NPE的bcz。而是調用上下文的靜態變量來獲取資源,您可以調用Resource r = getResource();和代碼將正常工作 –
是的,謝謝你的回答。我總是得到正常值,而不是空值。但我無法更改佈局大小。如果我在async類中插入這段代碼,下載圖像併爲_thumbImage_創建位圖,那麼代碼將正常工作,但它對我來說不正確:) –