【问题标题】:ScaleType in ImageView not workingImageView 中的 ScaleType 不起作用
【发布时间】:2016-10-20 18:30:41
【问题描述】:

我正在尝试使用 ViewPager 和 Volley 的 NetworkImageView 制作图片库。 viewpager 和图像检索一切正常。但是当我将位图放在 NetworkImageView 中时,图像不会被拉伸以填充 NetworkImageView 的大小。使用我的另一个 ImageView,设置 scaleType 就可以了。

<com.android.volley.toolbox.NetworkImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="fitXY" />

我的 xml 文件

public static class SwipeFragment extends Fragment {

    ImageLoader imageLoader = AppController.getInstance().getImageLoader();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View swipeView = inflater.inflate(R.layout.swipe_fragment, container, false);
        NetworkImageView imageView = (NetworkImageView) swipeView.findViewById(R.id.imageView);
        Bundle bundle = getArguments();
        int position = bundle.getInt("position");
        if (imageLoader == null) {
            imageLoader = AppController.getInstance().getImageLoader();
        }
        imageView.setImageUrl(fotoUrl.get(position), imageLoader);
        return swipeView;

    }

    static SwipeFragment newInstance(int position) {
        SwipeFragment swipeFragment = new SwipeFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("position", position);
        swipeFragment.setArguments(bundle);
        return swipeFragment;
    }
}

我的 java

对这个问题有任何想法吗? 我也尝试将 scaleType 更改为 fitCenter 但结果仍然相同。提前谢谢你。

【问题讨论】:

  • 这适用于所有带有 wrap_content 宽度和高度缩放的 ImageView 不适用。不特定于 Volley 的 ImageView。

标签: android imageview android-volley networkimageview scaletype


【解决方案1】:

我认为您的问题是因为用于宽度和高度的 wrap_content 值。尝试使用下面的代码,它应该可以工作。

<com.android.volley.toolbox.NetworkImageView
    android:id="@+id/imageView"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:scaleType="fitXY" />

当你说 wrap_content 这意味着你要求视图是相同的 图像的高度和宽度,因此缩放不适用。当你 固定宽度和高度,然后您可以应用 fitXY 比例类型。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多