問題描述
當圖像的寬度小於顯示器的寬度時,如何在視圖尋呼機內對齊圖像視圖的中心? (How to align center an image view inside a view pager when the image's width is less than the display's?)
我已經處理了幾個小時了。我需要一些幫助。我在 ViewPager 中有這個 ImageView。除了圖像無法達到顯示寬度外,一切都很好。我希望它水平居中,但無論我更改什麼設置,我都無法使其工作。
我使用了佈局參數,setRule,...由於 ImageView 沒有 setGravity,我應該選擇哪種方法? 首先新建一個線性或相對佈局,然後將圖像視圖添加到其中?沒有更合理的方法來讓 ImageView 對齊中心嗎?
這是我在 ViewPager 的適配器中的代碼:
public Object instantiateItem(final ViewGroup container, final int position) { if (context == null) return null; final ImageView imageView = new ImageView(context); if (propertyImagesIDs == null || propertyImagesIDs.length == 0 || context == null) { return null; } new PropertyPhotoProxy().run(new Response.Listener<Photo>() { @Override public void onResponse(Photo photo) { imageView.setImageBitmap(photo.getBitmap()); imageView.setScaleType(ImageView.ScaleType.FIT_START); ((ViewPager) container).addView(imageView, 0); } }, new DefaultErrorListener(), propertyImagesIDs[position]); return imageView; }
這是如何圖像在屏幕上對齊,無論我更改什麼設置。