當圖像的寬度小於顯示器的寬度時,如何在視圖尋呼機內對齊圖像視圖的中心? (How to align center an image view inside a view pager when the image's width is less than the display's?)


問題描述

當圖像的寬度小於顯示器的寬度時,如何在視圖尋呼機內對齊圖像視圖的中心? (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;
}

這是如何圖像在屏幕上對齊,無論我更改什麼設置。

FatimaBlackbelt)

參考文件

  1. How to align center an image view inside a view pager when the image's width is less than the display's? (CC BY‑SA 2.5/3.0/4.0)

#imageview #Android #android-layout #android-gravity #android-viewpager






相關問題

Android imageview 未在 TableRow 中顯示 (Android imageview not displaying in TableRow)

Android中的手勢 (Gestures in Android)

GridView kéo dài ImageView không đồng nhất (GridView Stretching ImageView Non-Uniformly)

ios在表格視圖單元格中視覺調整圖像大小 (ios visually resize image in a table view cell)

IndoorAtlas SDK 2.0:使用 Picasso 和自定義 ImageView (IndoorAtlas SDK 2.0: Using Picasso with custom ImageView)

當圖像的寬度小於顯示器的寬度時,如何在視圖尋呼機內對齊圖像視圖的中心? (How to align center an image view inside a view pager when the image's width is less than the display's?)

正確旋轉 ImageView 和 FrameLayout (Rotate ImageView and FrameLayout correctly)

setOnClickListener 沒有在圖像視圖上被調用 (setOnClickListener is not getting called on image view)

Android:擴展 onTouchEvent 以進行拖動的 ImageView (Android: ImageView that extends onTouchEvent for Drag)

將旋轉的文本放在圖像視圖上 (Put rotated text on an imageview)

如何在底部設置圖像視圖 (how to set imageview in bottom)

我如何使用數組來顯示匹配的 Imageview? (How Could I use array to show match Imageview?)







留言討論