<small id='1adTc'></small><noframes id='1adTc'>

      <i id='1adTc'><tr id='1adTc'><dt id='1adTc'><q id='1adTc'><span id='1adTc'><b id='1adTc'><form id='1adTc'><ins id='1adTc'></ins><ul id='1adTc'></ul><sub id='1adTc'></sub></form><legend id='1adTc'></legend><bdo id='1adTc'><pre id='1adTc'><center id='1adTc'></center></pre></bdo></b><th id='1adTc'></th></span></q></dt></tr></i><div id='1adTc'><tfoot id='1adTc'></tfoot><dl id='1adTc'><fieldset id='1adTc'></fieldset></dl></div>
        <bdo id='1adTc'></bdo><ul id='1adTc'></ul>
      <tfoot id='1adTc'></tfoot>

      1. <legend id='1adTc'><style id='1adTc'><dir id='1adTc'><q id='1adTc'></q></dir></style></legend>

        PageTransformer 转换中的 ViewPager 边距

        时间:2023-10-04

                <bdo id='56J9K'></bdo><ul id='56J9K'></ul>
              • <tfoot id='56J9K'></tfoot>
                1. <legend id='56J9K'><style id='56J9K'><dir id='56J9K'><q id='56J9K'></q></dir></style></legend>

                2. <i id='56J9K'><tr id='56J9K'><dt id='56J9K'><q id='56J9K'><span id='56J9K'><b id='56J9K'><form id='56J9K'><ins id='56J9K'></ins><ul id='56J9K'></ul><sub id='56J9K'></sub></form><legend id='56J9K'></legend><bdo id='56J9K'><pre id='56J9K'><center id='56J9K'></center></pre></bdo></b><th id='56J9K'></th></span></q></dt></tr></i><div id='56J9K'><tfoot id='56J9K'></tfoot><dl id='56J9K'><fieldset id='56J9K'></fieldset></dl></div>

                3. <small id='56J9K'></small><noframes id='56J9K'>

                    <tbody id='56J9K'></tbody>

                4. 本文介绍了PageTransformer 转换中的 ViewPager 边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 ViewPager,其中的每个视图都是卡片组上卡片的表示.每张卡片的边框上都有一个使用 ViewPager 边距的阴影:

                  I have a ViewPager in which each of it's views is a representation of card on a deck. Each card has a shadow on the border using the ViewPager margin:

                  cardsViewPager.setPageMargin(getResources().getDisplayMetrics().widthPixels / 20);
                  cardsViewPager.setPageMarginDrawable(R.drawable.shadow);
                  

                  它按预期工作.

                  但是,如果我添加一个 PageTransformer 以便右侧的卡片将堆叠在左侧的卡片之上:

                  But, if I add a PageTransformer so that the cards on the right will stack on top of the cards on the left:

                  public class ScalePageTransformer implements PageTransformer {  
                      private final ViewPager mViewPager;
                  
                      public ScalePageTransformer(ViewPager viewPager) {
                          this.mViewPager = viewPager;
                      }
                  
                      @Override
                      public void transformPage(View page, float position) {
                          if (position <= 0) {
                              int pageWidth = mViewPager.getWidth();
                              final float translateValue = position * -pageWidth;
                              if (translateValue > -pageWidth) {
                                  page.setTranslationX(translateValue);
                              } else {
                                  page.setTranslationX(0);
                              }
                          }
                      }
                  }
                  

                  我这样做是:

                  cardsViewPager.setPageTransformer(false, new ScalePageTransformer(cardsViewPager));
                  

                  但是现在,边距没有出现.如果我在 PageTransformer 上有一个缩小效果,我可以看到当前卡片何时被缩小,可绘制的边距低于屏幕上的当前卡片.这是一张描述正在发生的事情的图片:

                  But now, the margin does not appear. If I had a zoom out effect on the PageTransformer, I can see when the current card is being scaled down, that the margin drawable is below the current card on the screen. Here is a pic to describe what's happening:

                  蓝卡在红卡之上从右向左刷.由于红牌有比例变换,我们可以看到它后面的黑色可绘制的边距.

                  The blue card is being swiped from the right to left on top of the red card. Since the red card has a scale transformation, we can see the margin drawable in black behind it.

                  有没有办法强制可抽取的边距位于红牌之上?这不应该是默认行为吗?

                  Is there a way to force the margin drawable to be on top of the red card? Shouldn't this be the default behavior?

                  推荐答案

                  改成

                  cardsViewPager.setPageTransformer(true, new ScalePageTransformer(cardsViewPager));
                  

                  第一个参数是绘制顺序

                  这篇关于PageTransformer 转换中的 ViewPager 边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:'IllegalStateException: Activity 已被销毁'当 Activity 重启后 下一篇:AdMob AdView 和 ViewPager?

                  相关文章

                  <small id='GrUAf'></small><noframes id='GrUAf'>

                  • <bdo id='GrUAf'></bdo><ul id='GrUAf'></ul>

                    <legend id='GrUAf'><style id='GrUAf'><dir id='GrUAf'><q id='GrUAf'></q></dir></style></legend>

                    <tfoot id='GrUAf'></tfoot>
                    1. <i id='GrUAf'><tr id='GrUAf'><dt id='GrUAf'><q id='GrUAf'><span id='GrUAf'><b id='GrUAf'><form id='GrUAf'><ins id='GrUAf'></ins><ul id='GrUAf'></ul><sub id='GrUAf'></sub></form><legend id='GrUAf'></legend><bdo id='GrUAf'><pre id='GrUAf'><center id='GrUAf'></center></pre></bdo></b><th id='GrUAf'></th></span></q></dt></tr></i><div id='GrUAf'><tfoot id='GrUAf'></tfoot><dl id='GrUAf'><fieldset id='GrUAf'></fieldset></dl></div>