viewpager 图片适配

float ratio=502/185f;

 ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);



        //代码动态适配,及其常用的应用场景
        ViewGroup.LayoutParams layoutParams = viewPager.getLayoutParams();

        //像素宽度
        layoutParams.width = getResources().getDisplayMetrics().widthPixels;
        layoutParams.height = (int) (layoutParams.width/ratio);

        viewPager.setLayoutParams(layoutParams);

你可能感兴趣的:(viewpager 图片适配)