Android:ViewPager 卡在视图之间

2024-01-27

我有一个在片段之间滑动的 ViewPager。我正在使用 FragmentStatePagerAdapter 将 Fragment 提供给 ViewPager。如果用户以正常速度向左滑动,然后快速向右滑动,他们可能会使 ViewPager 进入一种奇怪的状态,其中显示多个 Fragment。

例如,如果用户在片段 A 上,然后以正常速度向左滑动到片段 B,然后快速向右滑动返回到片段 A,则屏幕上会同时显示片段 A 和 B。

有人知道为什么会发生这种情况,或者有什么好的方法来防止这种情况发生吗?

Here's what it looks like: enter image description here

这是我在 XML 中的 ViewPager 定义:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

<com.company.views.CustomActionBar
    android:id="@+id/customActionBar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/height_actionbar"
    android:layout_alignParentTop="true"/>

<android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/customActionBar"/>

另外,我记录了 onPageChangeListener() 的输出,并注意到当 ViewPager 卡在视图之间时,它报告的 positionOffset 为 0。这是 ViewPager 的值,当它落在这个位置时,它从 STATE_DRAGGING 转换到 STATE_SETTLING 到 STATE_IDLE奇怪的状态:

状态 = 0 前状态:2 位置:1 位置偏移:0.0

状态 = 1 前状态:0 位置:1 位置偏移:0.0

状态 = 2 前状态:1 位置:1 位置偏移:0.4069444

状态 = 0 前状态:2 位置:2 位置偏移:0.0

因此,看起来 ViewPager 正在向我报告错误的positionOffset。

完整的示例代码活动和适配器:

public class ActivityBagelProfileViewer extends CustomAbstractFragmentActivity
    implements CustomActionBarContract, ListenerProgress, ListenerSync
{
public static final String EXTRA_BAGEL_INDEX = "BAGEL";

public static final int REQUEST_CODE_BAGEL_PROFILE_VIEWER = 4000;
public static final int RESULT_GO_TO_PASS_FLOW = 12;
public static final int RESULT_GO_TO_LIKE_FLOW = 14;
public static final int RESULT_GO_TO_SEE_MORE_BAGELS = 16;

private ViewPager mProfilesViewPager;
private CustomActionBar mCustomActionBar;
private int mViewPagerPosition;

private DialogProgress mDialogProgress;

private BagelViewPagerAdapter mAdapterBagelViewPager;
private List<Bagel> mListBagels;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    Logger.d("ENTER");

    super.onCreate(savedInstanceState);

    if (ManagerGive.IS_BRANCH_SESSION_OPEN == false)
    {
        ManagerGive.initializeBranchMetricsSession();
    }

    setContentView(R.layout.activity_with_viewpager);

    mCustomActionBar = (CustomActionBar) findViewById(R.id.customActionBar);
    mCustomActionBar.setMenu(this);

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

    if (getIntent().getExtras() != null)
    {
        mViewPagerPosition = getIntent().getExtras().getInt(EXTRA_BAGEL_INDEX, 0);
    }
}

@Override
protected void onStop()
{
    super.onStop();
    ManagerGive.closeBranchMetricsSession();
}

public void onIconClick(View view)
{
    Logger.d("ENTER");
    finishWithAnimation();
}

private void finishWithAnimation()
{
    setResult(RESULT_OK);
    finish();
    overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_to_right);
}

@Override
public void onBackPressed()
{
    if (!super.handleBackPressedEvent())
    {
        finishWithAnimation();
    }
}


private void setupNewAdapter()
{
    mListBagels = Bakery.getInstance().getManagerBagel().getCopyOfBagelsWithoutCurrent();
    mAdapterBagelViewPager = new BagelViewPagerAdapter(getSupportFragmentManager(), mListBagels, this);
    mProfilesViewPager.setAdapter(mAdapterBagelViewPager);

    mProfilesViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener()
    {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
        {
        }

        @Override
        public void onPageSelected(int position)
        {
            setActionBar(position);
            mViewPagerPosition = position;
        }

        @Override
        public void onPageScrollStateChanged(int state)
        {
        }
    });

    mProfilesViewPager.setCurrentItem(mViewPagerPosition, false);
}

@Override
protected void onResume()
{
    Logger.d("ENTER");
    super.onResume();

    Bakery.getInstance().getManagerSyncData().addListener(this);

    if (mProfilesViewPager.getAdapter() == null)
    {
        Logger.d("Adapter null. Setting new adapter");
        setupNewAdapter();
    }
    else
    {
        if (mProfilesViewPager.getAdapter().getCount() !=
                Bakery.getInstance().getManagerBagel().getCopyOfBagelsWithoutCurrent().size())
        {
            Logger.d("Bagel list in Bakery changed size. Setting new adapter");
            setupNewAdapter();
        }
    }

    if (mListBagels.size() > 0)
    {
        setActionBar(mViewPagerPosition);
        mDialogProgress = new DialogProgress(this);
    }
    else
    {
        //kv Something has gone terribly wrong if we don't have any Bagels, just finish
        finish();
    }
}

private void setActionBar(int bagelIndex)
{
    Logger.d("bagelIndex=" + bagelIndex);

    Bagel bagel = mListBagels.get(bagelIndex);

    //kv If this is our current bagel and we haven't taken action yet, then show timer
    if (Bakery.getInstance().getManagerBagel().getCurrentBagel() == bagel
            && bagel.getAction() != Bagel.ACTION_LIKED && bagel.getAction() != Bagel.ACTION_PASSED)
    {
        Logger.d("Setting up #timer in action bar");
        mCustomActionBar.startTimeLeftTimer(DateUtils.getMillisFromUtc(bagel.getEndDate()),
                this, new ListenerTimer()
                {
                    @Override
                    public void onTimerExpired()
                    {
                        Logger.d("ENTER");
                        Bakery.getInstance().getManagerSyncData().performSync(null, false);
                    }
                }, mCustomActionBar.getTextViewTimeLeft(), R.string.timer_blank);
        mCustomActionBar.setLabel(R.string.time_left);
        mCustomActionBar.hideTitle();
    }
    //kv Otherwise show date
    else
    {
        mCustomActionBar.setTitle(DateUtils.getLocalizedDateFromStringDate(bagel.getStartDate(), DateUtils.DATE_WITH_TIME_PATTERN));
        mCustomActionBar.stopTimeLeftTimer();
        mCustomActionBar.hideTimeLeft();
    }
}

@Override
protected void onSaveInstanceState(Bundle outState)
{
    super.onSaveInstanceState(outState);
    outState.putInt(EXTRA_BAGEL_INDEX, mViewPagerPosition);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
    Logger.d("ENTER");

    super.onRestoreInstanceState(savedInstanceState);
    if (savedInstanceState.containsKey(EXTRA_BAGEL_INDEX))
    {
        mViewPagerPosition = savedInstanceState.getInt(EXTRA_BAGEL_INDEX);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    Logger.d("requestCode=" + requestCode + ", resultCode=" + resultCode + ", data=" + data);

    switch (requestCode)
    {
        case ActivityBeanShop.REQUEST_CODE:
            if (resultCode == Activity.RESULT_OK && data != null)
            {
                //fp user purchased sufficient beans to resume their transaction
                PurchaseType interruptedPurchaseType = (PurchaseType) data.getSerializableExtra(ActivityBeanShop.EXTRA_PURCHASE_TYPE);

                switch (interruptedPurchaseType)
                {
                    case BONUS_BAGEL:
                    case OPEN_SESAME:
                    case REMATCH:
                        Bundle bundle = new Bundle();
                        bundle.putSerializable(ManagerPurchase.EXTRA_PURCHASE_TYPE, interruptedPurchaseType);
                        ManagerEvents.notifyListeners(EventType.BEAN_TRANSACTION_FOR_FEATURE_UNLOCK_COMPLETE, bundle);
                        Logger.d("Notified listeners about #purchase bean transaction, can now resume feature #purchase");
                        break;

                    default:
                        Logger.w("Unrecognized purchase type: " + interruptedPurchaseType.getItemName());
                }
            }

            break;
        default:
            Logger.w("Could not recognize code: " + requestCode);
    }
}

@Override
public int getTitleId()
{
    return R.string.bagel_action_checked;
}

@Override
public int getIconId()
{
    return R.drawable.selector_icon_up;
}

@Override
public void showProgress(int stringId)
{
    mDialogProgress.setText(stringId);
    mDialogProgress.show();
}

@Override
public void dismissProgress()
{
    ViewUtils.safelyDismissDialog(mDialogProgress);
}

public void setActionBar()
{
    setActionBar(mViewPagerPosition);
}

@Override
public void onSyncComplete()
{
    Logger.d("ENTER");
    mListBagels = Bakery.getInstance().getManagerBagel().getCopyOfBagelsWithoutCurrent();
    mAdapterBagelViewPager.setBagels(mListBagels);
}

public boolean isShowingThisBagel(Bagel bagel)
{
    Bagel currentlyShownBagel = mListBagels.get(mViewPagerPosition);
    return bagel == currentlyShownBagel;
}

private static class BagelViewPagerAdapter extends FragmentStatePagerAdapter
{
    private List<Bagel> mBagels;
    private ListenerProgress mListenerProgress;

    public BagelViewPagerAdapter(FragmentManager fragmentManager, List<Bagel> bagels,
                                 ListenerProgress listenerProgress)
    {
        super(fragmentManager);
        Logger.d("bagels=" + bagels);
        this.mBagels = bagels;
        mListenerProgress = listenerProgress;
    }

    @Override
    public Fragment getItem(int i)
    {
        Logger.d("i=" + i);
        UserProfile myProfile = Bakery.getInstance().getManagerUserProfile().getMyOwnProfile();
        FragmentProfile fragment = FragmentProfile.newInstance(mBagels.get(i), false, myProfile);
        fragment.setListenerProgress(mListenerProgress);
        return fragment;
    }

    @Override
    public int getCount()
    {
        return mBagels.size();
    }

    public void setBagels(List<Bagel> bagels)
    {
        mBagels = bagels;
        notifyDataSetChanged();
    }
}
}

下面是每个片段布局的 XML 布局代码(必须删除 SO 字符限制的一些 b/c):

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scrollView">

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="-0.5dp"
    android:orientation="vertical"
    android:animateLayoutChanges="true"
    android:id="@+id/profile_top_container">

    <!-- Photos section with pager/carousel -->
    <FrameLayout
        android:id="@+id/photoViewpagerContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.coffeemeetsbagel.views.CustomAsShitViewPager
            android:id="@+id/pager_profile_images"
            xmlns:android="http://schemas.android.com/apk/res/android"
            app:aspectRatio="@integer/photo_ratio_height_over_width"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <LinearLayout
            android:id="@+id/linearLayout_bulletsAndFriendsContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:gravity="bottom">

            <com.coffeemeetsbagel.views.CustomTextView
                android:id="@+id/textView_stamp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="invisible"
                app:customFont="Raleway-Bold.ttf"
                android:layout_gravity="end"
                android:textSize="@dimen/text_stamp"
                android:paddingTop="@dimen/margin_large"
                android:layout_marginEnd="@dimen/margin_xxxxxsmall"
                android:layout_marginRight="@dimen/profile_margin_smaller"/>

            <!-- photo circle indicators -->
            <com.viewpagerindicator.CirclePageIndicator
                android:id="@+id/bullet_indicators"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/circle_indicator_margin_bottom"
                android:clickable="false"
                app:fillColor="@color/blue_cmb"
                app:pageColor="@color/gray_background"
                app:radius="@dimen/circle_indicator_radius"
                app:strokeWidth="0dp"/>

            <!-- container for mutual friends strip -->
            <RelativeLayout
                android:id="@+id/relativeLayout_mutual_friends_container"
                android:layout_width="match_parent"
                android:layout_height="@dimen/baseline_grid_component_touchable"
                android:background="@color/white_transparent"
                android:visibility="gone">

                <com.coffeemeetsbagel.views.CustomTextView
                    android:id="@+id/textView_mutual_friends_label"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentLeft="true"
                    style="@style/profile_mutual_friends_text"/>

                <LinearLayout
                    android:id="@+id/linearLayout_mutual_friends_icons"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:orientation="horizontal"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_marginEnd="@dimen/baseline_grid_small"
                    android:layout_marginRight="@dimen/baseline_grid_small"
                    android:layout_centerVertical="true">

                    <ImageView
                        android:id="@+id/imageView_icon0"
                        android:layout_width="@dimen/baseline_grid_component_touchable"
                        android:layout_height="@dimen/baseline_grid_component_touchable"
                        android:padding="@dimen/typography_smallest"
                        android:background="@color/transparent"
                        android:visibility="gone"/>

                    <ImageView
                        android:id="@+id/imageView_icon1"
                        android:layout_width="@dimen/baseline_grid_component_touchable"
                        android:layout_height="@dimen/baseline_grid_component_touchable"
                        android:background="@color/transparent"
                        android:padding="@dimen/typography_smallest"
                        android:visibility="gone"/>

                    <ImageView
                        android:id="@+id/imageView_icon2"
                        android:layout_width="@dimen/baseline_grid_component_touchable"
                        android:layout_height="@dimen/baseline_grid_component_touchable"
                        android:background="@color/transparent"
                        android:padding="@dimen/typography_smallest"
                        android:visibility="gone"/>
                </LinearLayout>
            </RelativeLayout>
        </LinearLayout>
    </FrameLayout>

    <!-- Buttons section with User Actions for pass / like-->
    <LinearLayout
        android:id="@+id/linearLayout_buttons_pass_like"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/baseline_grid_smaller"
        android:layout_marginLeft="@dimen/baseline_grid_small"
        android:layout_marginRight="@dimen/baseline_grid_small"
        android:layout_marginTop="@dimen/baseline_grid_medium"
        android:orientation="horizontal"
        android:visibility="gone">

        <ImageView
            android:id="@+id/button_pass"
            android:layout_width="0dp"
            android:layout_height="@dimen/profile_action_button_height"
            android:layout_weight="1"
            android:background="@drawable/ripple_button_pass"
            android:clickable="true"
            android:src="@drawable/icon_pass_pressed"
            android:scaleType="center"
            android:layout_marginRight="@dimen/margin_small"/>

        <ImageView
            android:id="@+id/button_like"
            android:layout_width="0dp"
            android:layout_height="@dimen/profile_action_button_height"
            android:layout_weight="1"
            android:background="@drawable/ripple_button_like"
            android:clickable="true"
            android:src="@drawable/icon_like_pressed"
            android:scaleType="center"
            android:layout_marginLeft="@dimen/margin_small"/>
    </LinearLayout>

    <!-- Buttons section with User Actions for rematch / give-->
    <LinearLayout
        android:id="@+id/linearLayout_buttons_rematch_give"
        android:layout_width="match_parent"
        android:layout_height="@dimen/give_ten_button_height"
        android:layout_marginBottom="@dimen/baseline_grid_smaller"
        android:layout_marginLeft="@dimen/baseline_grid_small"
        android:layout_marginRight="@dimen/baseline_grid_small"
        android:layout_marginTop="@dimen/baseline_grid_medium"
        android:orientation="horizontal"
        android:gravity="center"
        android:visibility="gone">

        <com.coffeemeetsbagel.views.CustomTextView
            android:id="@+id/textView_rematch"
            android:layout_width="@dimen/zero_dip"
            android:layout_height="match_parent"
            android:layout_marginRight="@dimen/give_take_button_margin_side"
            android:layout_weight="1"
            style="@style/button_give_take_rematch"
            android:text="@string/rematch"/>

        <com.coffeemeetsbagel.views.CustomTextView
            android:id="@+id/text_view_give_with_rematch"
            android:layout_width="@dimen/zero_dip"
            android:layout_weight="1"
            android:layout_height="match_parent"
            style="@style/button_give_take_rematch"
            android:text="@string/give"/>
    </LinearLayout>

    <com.coffeemeetsbagel.views.CustomTextView
        android:id="@+id/textView_they_like_you"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/icon_like_alert"
        android:drawablePadding="@dimen/margin_xxsmall"
        style="@style/profile_info_item_value"
        android:layout_marginLeft="@dimen/margin_med"
        android:paddingTop="@dimen/baseline_grid_smaller"/>

    <ViewStub
        android:id="@+id/viewStub_profile_feedback"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout="@layout/profile_feedback"/>

    <!-- Profile information table -->
    <!-- Name -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  style="@style/profile_info_item_layout_margins"
                  android:paddingTop="@dimen/baseline_grid_smaller"
                  android:orientation="horizontal">

        <com.coffeemeetsbagel.views.CustomTextView
            android:text="@string/profile_info_label_name"
            style="@style/profile_info_item_label"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <com.coffeemeetsbagel.views.CustomTextView
            android:id="@+id/profile_info_value_name"
            style="@style/profile_info_item_value"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>
    </LinearLayout>

    <!-- Age -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  style="@style/profile_info_item_layout_margins"
                  android:orientation="horizontal">

        <com.coffeemeetsbagel.views.CustomTextView
            android:text="@string/profile_info_label_age"
            style="@style/profile_info_item_label"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />

        <com.coffeemeetsbagel.views.CustomTextView
            android:id="@+id/profile_info_value_age"
            style="@style/profile_info_item_value"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>
    </LinearLayout>

    <!-- Location -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  style="@style/profile_info_item_layout_margins"
                  android:orientation="horizontal">

        <com.coffeemeetsbagel.views.CustomTextView
            android:text="@string/location"
            style="@style/profile_info_item_label"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />

        <com.coffeemeetsbagel.views.CustomTextView
            android:id="@+id/profile_info_value_location"
            style="@style/profile_info_item_value"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>
    </LinearLayout>

    <!-- Ethnicity -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  style="@style/profile_info_item_layout_margins"
                  android:orientation="horizontal">

        <com.coffeemeetsbagel.views.CustomTextView
            android:text="@string/profile_info_label_ethnicity"
            style="@style/profile_info_item_label"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />

        <com.coffeemeetsbagel.views.CustomTextView
            android:id="@+id/profile_info_value_ethnicity"
            style="@style/profile_info_item_value"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>
    </LinearLayout>

    <!-- Height -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  style="@style/profile_info_item_layout_margins"
                  android:orientation="horizontal">

        <com.coffeemeetsbagel.views.CustomTextView
            android:text="@string/profile_info_label_height"
            style="@style/profile_info_item_label"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />

        <com.coffeemeetsbagel.views.CustomTextView
            android:id="@+id/profile_info_value_height"
            style="@style/profile_info_item_value"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>
    </LinearLayout>

    <!-- Religion -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  style="@style/profile_info_item_layout_margins"
                  android:orientation="horizontal">

        <com.coffeemeetsbagel.views.CustomTextView
            android:text="@string/profile_info_label_religion"
            style="@style/profile_info_item_label"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />

        <com.coffeemeetsbagel.views.CustomTextView
            android:id="@+id/profile_info_value_religion"
            style="@style/profile_info_item_value"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>
    </LinearLayout>

    <!-- Occupation -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  style="@style/profile_info_item_layout_margins"
                  android:orientation="horizontal">

        <com.coffeemeetsbagel.views.CustomTextView
            android:text="@string/profile_info_label_occupation"
            style="@style/profile_info_item_label"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />

        <com.coffeemeetsbagel.views.CustomTextView
            android:id="@+id/profile_info_value_occupation"
            style="@style/profile_info_item_value"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"/>
    </LinearLayout>

    <!-- Employer -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  style="@style/profile_info_item_layout_margins"
                  android:orientation="horizontal">

...


我注意到,如果我有一些动画,我会看到这个问题动画布局更改。只需在 xml 文件中停用它,即可防止页面卡在中间。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android:ViewPager 卡在视图之间 的相关文章

  • Numpy:查找两个 3-D 数组之间的欧几里德距离

    给定两个维度为 2 2 2 的 3 D 数组 A 0 0 92 92 0 92 0 92 B 0 0 92 0 0 92 92 92 如何有效地找到 A 和 B 中每个向量的欧几里得距离 我尝试过 for 循环 但速度很慢 而且我正在按 g
  • 从一个 NSManagedObjectContext 保存的更改不会反映在主 NSManagedObjectContext 上

    我有一个主NSManagedObjectContext是在appDelegate 现在 我正在使用另一个NSManagedObjectContext用于编辑 添加新对象而不影响主对象NSManagedObjectContext 直到我拯救它
  • 就地改变 numpy 函数输出数组

    我正在尝试编写一个对数组执行数学运算并返回结果的函数 一个简化的例子可以是 def original func A return A 1 A 1 为了加速并避免为每个函数调用分配新的输出数组 我希望将输出数组作为参数 并就地更改它 def
  • 如何解决 Xcode 7 中的 No Type or Protocol Named 错误?

    我试图passing从第二个开始的值class我正在使用的头等舱protocol and delegate过程 每当我运行我的程序时 我都会遇到以下问题 No Type or Protocol Named locateMeDelegate
  • 理解“窗口”对象[重复]

    这个问题在这里已经有答案了 可能的重复 JS 窗口全局对象 https stackoverflow com questions 10035771 js window global object 如何window对象工作 我知道它是顶级对象并
  • Liftweb 环境中的后台任务

    我必须编写守护进程 并且我想使用模型来连接到数据库和一些有用的 Lift 类 是否可以运行 Rails 的 rake 任务的模拟 Scala 社区组上也有类似的问题 答案是使用Actors来做后台处理
  • rspec 在需要存根的私有方法中测试私有方法

    Simplecov 检测到我遗漏了一些测试lib api verson rb class class ApiVersion def initialize version version version end def matches req
  • 整个程序可以是不可变的吗? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我熟悉不可变性并且可以设计不可变类 但我主要拥有学术知识 缺乏实践经验 请参考上面的链接图片 尚不允许嵌入 从下往上看 学生需要新地址
  • Apache Zeppelin 安装 grunt 构建错误

    我的配置如下 Ubuntu 15 04 Java 1 7 Spark 1 4 1 Hadoop 2 7 Maven 3 3 3 我正在尝试从 github 成功克隆 Apache Zeppelin 并使用以下命令后安装它 mvn clean
  • ASP.NET 中的 ThreadStaticAttribute

    我有一个需要存储的组件static每个线程的值 它是一个通用组件 可以在许多场景中使用 而不仅仅是在 ASP NET 中 我想用 ThreadStatic 属性来实现我的目标 假设它在 ASP NET 场景中也能正常工作 因为我假设每个请求
  • 构建 AOSP 5.1 时出现 API 更改错误

    目前正在尝试构建 android 5 1 0 r5 我已经检查了来源并且没有做任何修改 但是 编译时出现以下错误 Checking API checkpublicapi current out target common obj PACKA
  • 在 C++ 中,将 float 转换为 double 再转换回 float 是否给出相同的值

    假设在下面的代码中 float f1 double d1 static cast
  • 致命:Jenkins IIS ID 无效

    我正在尝试设置 Jenkins 从 bitbucket 中提取并构建一个项目 我在 IIS 8 5 Server 2012 r2 上使用它 我已经设置了 Git 和 Bitbucket 插件 我已经建立了一个包含以下内容的项目 Branch
  • 404 路由无法匹配请求的 URL

    我刚刚开始学习zend 框架 questions tagged zend framework并遵循此用户指南 http framework zend com manual 2 3 en index html 我能够成功安装zend skel
  • create() 时不会调用观察者

    我有一个Ember Mixin它观察到它的属性之一 这里bar baz 我扩展了这个 Mixin 并设置了bar baz in the create 参数 但我的观察者没有被调用 这是我的代码 App FooMixin Ember Mixi
  • Google Maps JavaScript API v3 方向功能

    我使用 Google Maps js API v3 我可以根据路径点显示方向this http code google com intl hu apis maps documentation directions Waypoints 我想要
  • MSBuild 找不到 resgen.exe

    我有一台 VM 机器 我在其中复制了 SDK 文件和路径 转到注册表并将密钥添加到注册表中 但我不断收到错误 resgen exe找不到 C Windows Microsoft NET Framework v4 0 30319 Micros
  • JSF 1.2:如何在同一视图上的回发中保持请求范围的托管 bean 处于活动状态?

    是否可以在同一页面上的回发过程中保持请求作用域的 bean 处于活动状态 一般的问题是 bean 在请求结束时被丢弃 并在每次表单提交时重新创建 例如动态操作背后的布尔值disabled readonly and rendered重置为默认
  • Ruby/Rails/Rack 代码中的“use”关键字/单词

    最近我偶然在Ruby代码中看到这个词 use 当我正在查看一些与goliath https github com postrank labs goliath 中间件等 看起来它不同于include extend and require 有人
  • 在 Python 中窗口“失焦”时读取 HID 输入

    我在一个问题上苦苦挣扎了好几天 但无法让它发挥作用 我刚刚开始使用 python 现在已经面临着我在这个项目中将面临的最大问题 情况是这样的 我必须编写一个扫描条形码的程序 将其传达给在线服务并打印 PDF 这一切都很好 但我也想在窗口 失

随机推荐

  • SCons 不会清除所有文件

    我有一个包含 builds 目录的文件系统 每个目录都包含一个名为 build info xml 的文件 然而 一些构建发生在构建脚本生成 build info xml 之前 因此在这种情况下 我有一个有点不平凡的 SCons SConst
  • execCommand insertHTML 中断存储的 window.getSelection()

    当使用在页面中选择文本和恢复所选文本的方法时 我发现运行execCommand insertHTML in Between 会导致存储的选择中断 这是如何选择和恢复文本的示例 Get Selection var sel window get
  • 将php文件加载到布局模板中?

    我正在开发我的第一个 php 网站 我遇到了一个我无法解决的问题 我试图拥有一个包含我的结构的 php 页面 以及其他在其中注入 html 的页面 同时保留 url 更改 以便我仍然可以直接链接页面 到目前为止 这就是我正在做的事情 但似乎
  • ggmap 具有值的热图

    谁能帮我制作 ggmap 热图 我的数据 val Qtd lt c 34 10 11 7 55 18 33 16 16 249 nom State lt c Distrito Federal Bahia Ceara Espirito San
  • 突出显示 Jupyter 单元中的部分代码

    有没有办法突出显示 Jupyter 单元格的某些行 类似于下图的内容 我用照片编辑器创建的 我的意思不是用光标进行选择 而是永久性的选择 例如 当您想要突出显示新添加的代码时 这对于演示文稿非常有用 下面提供的 Jupyter 笔记本扩展允
  • 当我不知道创建时的最大大小时,如何使用 Lucene 的 PriorityQueue?

    我为 Lucene Net 构建了一个自定义收集器 但我不知道如何对结果进行排序 或分页 每次调用 Collect 时 我都可以将结果添加到内部 PriorityQueue 中 我认为这是执行此操作的正确方法 我扩展了 PriorityQu
  • Objective C - 如果没有什么不同就使用访问器

    在目标c中 如果使用getter和直接访问ivar做完全相同的事情 getter中没有延迟加载代码 它所做的只是返回ivar 您是否仍然使用访问器或直接访问ivar 因为有没有不同 为什么 编辑 我说的是课堂内部 直接使用 ivar 会带来
  • JNI:从 C++ 到 Java 传递字节

    HANDLE hFile CreateFileA C myfile zip GENERIC READ 0 NULL OPEN EXISTING FILE ATTRIBUTE NORMAL NULL const int size GetFil
  • 如何强制执行父子结构的生命周期?

    我正在为外部 C 库编写包装器代码 并且试图说服 Rust 编译器强制执行 Rust 代码本身未反映的外部生命周期限制 例如 一种类型的 不透明句柄 可以返回仅在父句柄的生命周期内有效的子句柄 我尝试过std marker PhantomD
  • iOS 禁用键盘 Tab 箭头

    我需要使用 JavaScript 甚至基于 Web 的应用程序元标记 如果有 来禁用 IOS 上的键盘选项卡箭头 我尝试了一些选项 但在选择菜单时遇到了问题 我也无法将所有 tabindex 恢复为 1 因为这会损害桌面和其他设备上的选项卡
  • 打字稿检查类型 A === 类型 B | C型

    在一个文件中我有这样的内容 export const all a b c d e f type AllKeysType typeof all export type AllKey keyof AllKeysType 在另一个文件中我有这样的
  • macOS 上的 RTLD_GLOBAL 和二级命名空间

    阅读 Apple 文档后执行 Mach O 文件 https developer apple com library content documentation DeveloperTools Conceptual MachOTopics 1
  • 有没有办法获取android应用程序的安装程序源

    我们如何才能获取在我们的设备上安装软件包的安装源信息 我想获取其他已安装应用程序的安装程序源 而不仅仅是我的应用程序 以验证其完整性 是的 您可以获得应用程序的安装程序 您可以使用以下命令获取安装程序的包名称获取安装程序源信息 https
  • 基于同一模型中的另一个外键动态限制 Django 模型中外键的​​选择

    我有这些模型 class UserProfile models Model name models CharField max length 100 class Dialog models Model belong to models Ma
  • 在 Clojure 中使用 Spectre 删除嵌套值

    假设我有一个像这样的 Clojure 映射 def mymap a 1 2 3 b c d 1 2 3 我想要一个函数 remove empties 生成一个新映射 其中删除 b mymap 中具有空序列作为值的条目 因此 remove e
  • 如何列出当前目录下的文件?

    我希望能够列出当前目录中的文件 我做了一些应该可以工作但不返回所有文件名的东西 File dir new File File filesList dir listFiles for File file filesList if file i
  • 设置目录和 VBA 中的 If Len(Dir(... 语句

    我有一个文件存在于该路径下 path folder1 folder2 datafile gdp 它是通过以下方式从 vba 调用的外部程序的输入 Sub RunProgram Dim wsh As Object SetCurrentDire
  • Java 中的 String.Format (.NET) 等效项?

    NET 也许只是VB NET 中的String Format将 0 1 转换为确定的字符串 例如 Dim St As String Test 0 1 Console WriteLine String Format St Text1 Text
  • 有没有办法抑制 FindBugs 对静态编织生成的代码生成警告?

    对于通过 EclipseLink 2 5 1 JPA 实体静态编织生成的代码 我从 FindBugs 2 0 2 和 Sonar 3 7 3 中得到了我认为是误报的信息 具体来说 我看到多次出现 ES COMPARING PARAMETER
  • Android:ViewPager 卡在视图之间

    我有一个在片段之间滑动的 ViewPager 我正在使用 FragmentStatePagerAdapter 将 Fragment 提供给 ViewPager 如果用户以正常速度向左滑动 然后快速向右滑动 他们可能会使 ViewPager