2

以上是我的问题截图。我只想在上下滑动时移除不透明度。当我向下滑动时,当前页面变为透明。我需要消除这种透明度。我没有扩展 ViewPager,而是扩展了活动。谁能给我这个问题的解决方案?

public class VerticalViewPager extends Activity  {

private static final float MIN_SCALE = 0.75f;
PagerAdapter adapter;
private static final float MIN_ALPHA = 0.75f;
private boolean a;






@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.verticalviewpager);

    fr.castorflex.android.verticalviewpager.VerticalViewPager verticalViewPager = (fr.castorflex.android.verticalviewpager.VerticalViewPager) findViewById(R.id.verticalviewpager);


    adapter = new MyCustomAdapter(VerticalViewPager.this, SplashScreen.newsidArray, SplashScreen.newsdescArray, SplashScreen.newstitleArray,
            SplashScreen.newsimageArray, SplashScreen.newsdateArray, SplashScreen.newsauthorArray, SplashScreen.newsurlArray);
    verticalViewPager.setOffscreenPageLimit(1);
    verticalViewPager.setAdapter(adapter);

    verticalViewPager.setPageTransformer(false, new PageTransformer() {


        @Override
        public void transformPage(View view, float position) {
            int pageWidth = view.getWidth();
            int pageHeight = view.getHeight();

            if (position <= -1.0F) {
                view.setAlpha(1);
                Log.e("1", "test1");
            } else if (position < 0F) {
                view.setAlpha(1);
                Log.e("2", "test2");
            } else if (position >= 0F) {
                view.setAlpha(0.9F - position);
                view.setTranslationY((int) ((float) (pageHeight) * -position));
                Log.e("3", "test3" + position);
            } else if (position > 1.0F) {
                view.setAlpha(1);
                // view.setTranslationX(position < 0 ? 0f : -pageHeight * position);

                Log.e("4", "test4");
            }


        }
    });


}


}
4

2 回答 2

0

请试试这个。而且您必须确认不使用setAlpha()任何地方进行页面布局。(例如布局xml)

verticalViewPager.setPageTransformer(false, new ViewPager.PageTransformer() {

        @Override
        public void transformPage(View view, float position) {
            int pageWidth = view.getWidth();
            int pageHeight = view.getHeight();

            if (position >= 0) {
                view.setTranslationY(position < 0 ? 0f : -pageHeight * position);
            }
        }
    });
于 2016-01-04T11:35:02.833 回答
0

我得到了答案,您需要为正在制作动画的视图设置背景。默认是透明的

android:background="#FFFFFF"
于 2020-04-18T11:28:20.500 回答