Java 片段切换降低了Android应用程序的速度

Java 片段切换降低了Android应用程序的速度,java,android,performance,android-fragments,memory-management,Java,Android,Performance,Android Fragments,Memory Management,我正在开发一款Android应用程序,它有三种支付模式的片段,即CardFragment,NetBankingFragment,WalletFragment 在NetBankingFragment中,我有多个基本上代表不同银行的图像视图 下面是我的XML代码,用于表示网络银行UI的片段\u nb\u视图 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="ht

我正在开发一款Android应用程序,它有三种支付模式的
片段,即CardFragmentNetBankingFragmentWalletFragment

NetBankingFragment中,我有多个基本上代表不同银行的
图像视图

下面是我的XML代码,用于表示网络银行UI的片段\u nb\u视图

<ScrollView
    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:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:padding="10dp"
    android:layout_marginTop="25dp"
    android:orientation="vertical"
    android:scrollbars="vertical"
    android:background="@drawable/new_card_form"
    tools:context=".activities.fragments.NetBankingFragment">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center">
    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/background_nb_button"
        android:padding="5dp"
        android:gravity="center">


        <TableRow
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginBottom="10dp">

            <ImageView
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:id="@+id/sbiButton"
                android:src="@drawable/sbilogo"
                android:layout_marginRight="10dp"/>

            <ImageView
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:id="@+id/axisButton"
                android:src="@drawable/axisbank"/>

        </TableRow>


        <TableRow
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginBottom="10dp">

         <ImageView
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:id="@+id/citiButton"
                android:src="@drawable/citilogo"
                android:layout_marginRight="10dp"/>


            <ImageView
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:id="@+id/hdfcButton"
                android:src="@drawable/hdfclogo"/>
        </TableRow>
    </TableLayout>
    </RelativeLayout>

</ScrollView>
这似乎表明,mainthread本身做了太多的处理,但我不知道其他方法如何做


请提供帮助。

在Android Studio中使用traceview工具,并对方法调用进行分析。好的。我已经做了,但是我如何解释数据呢?我是新来的Android发现问题出在图像上。使用更小的图像&像毕加索这样的图书馆解决了这个问题
import android.content.Context;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.res.ResourcesCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Spinner;

import org.json.JSONArray;


/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link NetBankingFragment.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link NetBankingFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class NetBankingFragment extends Fragment implements FormFragmentBehaviour {
    private int index;

    private int NUM_COL = 2;
    private int NUM_ROW = 3;

    private Button btn;

    private ImageView sbilogo, axislogo, citilogo, hdfclogo;

    private View FragView;

    private OnFragmentInteractionListener mListener;

    /**
     * Factory for our Fragment.
     * */
    public static NetBankingFragment newInstance(int index) {
        Bundle fragmentArgs = new Bundle();
        fragmentArgs.putInt("index", index);

        NetBankingFragment fragment = new NetBankingFragment();
        fragment.setArguments(fragmentArgs);

        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.index = getArguments().getInt("index");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        FragView = inflater.inflate(R.layout.fragment_net_banking, container, false);

        init();
        grayout();

        sbilogo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                setParticularGray((ImageView) v);
            }
        });

        axislogo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                setParticularGray((ImageView) v);
            }
        });

        citilogo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                setParticularGray((ImageView) v);
            }
        });

       hdfclogo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                setParticularGray((ImageView) v);
            }
        });




        return FragView;




    }



    public void setgray(ImageView imageView)
    {
        final ColorMatrix gray = new ColorMatrix();
        gray.setSaturation(0);

        final ColorMatrixColorFilter filter = new ColorMatrixColorFilter(gray);
        imageView.setColorFilter(filter);
    }





    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);


    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @Override
    public boolean validate() {
        return false;
    }

    @Override
    public void clearErrors() {

    }

    /**
     * This will show the various banks that are available after fetching from the EC backend.s
     * */
    public void showBanks(JSONArray banks) {

    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p/>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }

    //To Generate the buttons for Banks
    public void grayout()
    {
        setgray(sbilogo);
        setgray(axislogo);
        setgray(citilogo);
        setgray(hdfclogo);
    }

    public void init() {
        sbilogo = (ImageView) FragView.findViewById(R.id.sbiButton);
        axislogo = (ImageView) FragView.findViewById(R.id.axisButton);
        citilogo = (ImageView) FragView.findViewById(R.id.citiButton);
        hdfclogo = (ImageView) FragView.findViewById(R.id.hdfcButton);
    }


    public void setParticularGray(ImageView imgView)
    {
        grayout();

        final ColorMatrix color = new ColorMatrix();
        color.setSaturation(1);

        final ColorMatrixColorFilter filter = new ColorMatrixColorFilter(color);
        imgView.setColorFilter(filter);
    }
}
07-07 19:00:30.087 3453-3453/payment.ec.juspay.in.demoapp I/Choreographer: Skipped 44 frames!  The application may be doing too much work on its main thread.
07-07 19:00:30.399 3453-3453/payment.ec.juspay.in.demoapp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@9ac1206 time:39534547
07-07 19:00:30.399 3453-3453/payment.ec.juspay.in.demoapp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@40c0291 time:39534547
07-07 19:00:35.423 3453-3453/payment.ec.juspay.in.demoapp I/Choreographer: Skipped 33 frames!  The application may be doing too much work on its main thread.
07-07 19:12:47.792 3453-3453/payment.ec.juspay.in.demoapp I/art: Explicit concurrent mark sweep GC freed 9617(452KB) AllocSpace objects, 0(0B) LOS objects, 8% free, 82MB/90MB, paused 1.928ms total 78.116ms