簡體   English   中英

平板電腦和手機上的Android圖像

[英]Android image on tablets and phones

我有問題,我讓應用程序執行並且我希望圖像占據屏幕的同一部分(10英寸平板電腦和5英寸手機)。例如,我希望圖像在平板電腦和手機上占據一半的寬度...我知道ldpi hdpi xhdpi,但是這不是工作。你能幫我嗎?

我的標准尺寸圖像是320 x 200(對於手機),並將它們存儲在mdpi目錄中。 對於平板電腦,我將其尺寸調整為480 x 300:

        if (isTablet(getActivity())){  // tablets only
           debugLog( "display tablet image="+imagename);
           int resID = getResources().getIdentifier(imagename,"drawable", getActivity().getPackageName());                       // the corresponding resource id
           if (resID != 0) {
              Bitmap bmp=BitmapFactory.decodeResource(getResources(), resID);
              int width=480;
              int height=300;
              Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);
              ImageView imageView = (ImageView) getActivity().findViewById(R.id.tablet_image);  // the imageview to change
              //imageView.setImageResource(resID);
              imageView.setImageBitmap(resizedbitmap);
           }
        }

我這樣做是因為我有很多圖像,並且我不想存儲和維護每個圖像的兩個副本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM