Android - NavigationTabStrip动画无法顺利移动

时间:2016-10-21 10:59:29

标签: android xml android-fragments android-viewpager

我一直在我的应用中使用此库作为标签:https://material.uplabs.com/posts/navigationtabstrip

所以我在设置导航标签条的viewpager之前尝试了它并且它完美地工作并且在标签之间移动时点平滑动画但是在设置了寻呼机后它仍然在标签之间移动但是动画的内容出错了指出它变得迟钝而且它会运行两次,而不是只移动一次到另一个标签。

这是我使用navigationtabstrip的类:

公共类MainTabsActivity扩展了AppCompatActivity {

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

    assert getSupportActionBar() != null;
    getSupportActionBar().setElevation(0);

    RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.tabParentView);

    final NavigationTabStrip navigationTabStrip = (NavigationTabStrip) findViewById(R.id.nts);
    navigationTabStrip.setTabIndex(0);
    navigationTabStrip.bringToFront();

    relativeLayout.invalidate();

    final ViewPager viewPager = (ViewPager) findViewById(R.id.main_tabs_view_pager);
    viewPager.setOffscreenPageLimit(2);
    viewPager.setAdapter(new MainTabsAdapter(getSupportFragmentManager()));

    navigationTabStrip.setViewPager(viewPager);

    //navigationTabStrip.setOnPageChangeListener();

    //navigationTabStrip.setOnTabStripSelectedIndexListener();

}
}

这是它的xml文件:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_tabs_view_pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="60dp" />

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="60dp"
    app:elevation="15dp">

    <RelativeLayout
        android:id="@+id/tabParentView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.gigamole.navigationtabstrip.NavigationTabStrip xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/nts"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            app:nts_active_color="#ffffff"
            app:nts_animation_duration="400"
            app:nts_color="#29B6F6"
            app:nts_corners_radius="4dp"
            app:nts_factor="3"
            app:nts_gravity="bottom"
            app:nts_inactive_color="#B0BEC5"
            app:nts_size="14sp"
            app:nts_titles="@array/tabs"
            app:nts_type="point"
            app:nts_typeface="fonts/typeface.otf"
            app:nts_weight="7dp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="4dp"
            android:layout_below="@id/nts"
            android:layout_marginTop="-6dp"
            android:alpha="0.9"
            android:background="#D32F2F" />

    </RelativeLayout>

</android.support.design.widget.AppBarLayout>

这是viewpager适配器:

class MainTabsAdapter extends FragmentPagerAdapter {

MainTabsAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int index) {

    switch (index) {
        case 0:
            return new PrivateChatsFragment();

        case 1:
            return new PrivateChatsFragment();

        case 2:
            return new PrivateChatsFragment();

        default:
            return null;
    }
}

@Override
public int getCount() {
    return 3;
}
}

这是我在适配器中使用的片段:

import android.content.Context;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class PrivateChatsFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                         Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.private_chats_fragment, container, false);

    return rootView;
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
}
}

这是它的xml文件:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ahmed.bondmessenger.PrivateChatsFragment">

</RelativeLayout>

所以请帮忙吗?谢谢!

0 个答案:

没有答案