图像加载真的很慢吗? BottomNavigationView似乎引起问题

时间:2019-03-05 05:21:58

标签: android imageview bottomnavigationview

使用毕加索从互联网上加载随机图像,图像加载非常缓慢,设置也非常简单。删除BottomNavigationView可使图像加载超级顺畅。.这是什么问题? 下面的代码

public class MainActivity extends AppCompatActivity {
BottomNavigationView navi;
FragmentTransaction fragmentTransaction;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    switchFragment(new FragmentOne());
    navi = findViewById(R.id.navigation);
    navi.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {

            Fragment fragment;
            if (item.getItemId() == R.id.search) {
                item.setChecked(false);
                fragment = new FragmentTwo();
                switchFragment(fragment);
                return false;
            }
            return false;
        }
    });
}

private void switchFragment(Fragment fragment) {
    fragmentTransaction = getSupportFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.fragment_container, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}}

xml main:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="384dp"
    android:layout_height="457dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@color/colorAccent"
    app:itemBackground="@color/colorAccent"
    app:itemIconTint="@color/colorPrimary"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:menu="@menu/navigation_bar_menu" />


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

图片加载片段:

public class FragmentTwo extends Fragment {


private ImageView imageView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment2, container, false);

}


@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    imageView = getActivity().findViewById(R.id.imageView);

    Picasso.get().load("https://static1.squarespace.com/static/58e2c0e21b631bf0ffed01b9/596bddede4fcb5edd0e7b19d/5ad5375a2b6a28c200dea2ac/1523922823971/4683CDP.jpg").into(imageView);

    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

}}

已经找到解释为什么会发生这种情况的任何帮助,将不胜感激

0 个答案:

没有答案