活动加载缓慢

时间:2015-10-26 11:58:21

标签: android android-layout android-activity

我的应用程序中有大约50个活动。 但其中一项活动非常缓慢,我的意思是当我按下按钮进行该活动时,需要很长时间,有时最终会出现黑屏。 在那个活动上,我有一个按钮,如果我点击那个按钮,它需要很长时间才能执行。 代码很轻,只有一个Button,EditText和一个RatingBar。 还有其他人经历过吗?

我的Java代码

public class RateOrder extends AppCompatActivity {

Button submit;
RelativeLayout skip;
RatingBar rate;
EditText feedback;
SharedPreferences sp;
String toastText,ratevalue;
int res_code;
float rateevalue;
SweetAlertDialog pDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rate_order);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#6FD0EA")));
    skip=(RelativeLayout)findViewById(R.id.skip);
    submit=(Button)findViewById(R.id.ratebtn);
    sp=getSharedPreferences("medieazy",MODE_PRIVATE);
    pDialog=new SweetAlertDialog(this,SweetAlertDialog.PROGRESS_TYPE);
    pDialog.setTitleText("Please wait...");
    rate=(RatingBar)findViewById(R.id.ratingBar);
    feedback=(EditText)findViewById(R.id.feedbackTxt);

    Toast.makeText(getApplicationContext(),getIntent().getStringExtra("orderno"),Toast.LENGTH_LONG).show();
    if(getIntent().getStringExtra("from").equals("address")){
        skip.setVisibility(View.GONE);
        skip.setEnabled(false);
    }


    skip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(RateOrder.this,Login.class));
        }
    });


    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


          if(Utils.isNetworkAvailable(RateOrder.this)){
                if(rateevalue>0){
                    ratevalue=String.valueOf(rateevalue);
                    new SubmitRating().execute();
                }
              else{
                    Toast.makeText(getApplicationContext(),"Please rate",Toast.LENGTH_LONG).show();
                }

            }
            else{
                Toast.makeText(getApplicationContext(),"No Internet Connection",Toast.LENGTH_LONG).show();
            }
        }
    });

    rate.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating,
                                    boolean fromUser) {
            // TODO Auto-generated method stub
            rateevalue = rating;

            //  Toast.makeText(getApplicationContext(),ratevalue,Toast.LENGTH_LONG).show();

        }
    });
}

和我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:weightSum="10"
android:background="#ffffff"
android:orientation="vertical"
tools:context="app.aguai.medieazy.activities.RateOrder">


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="4"
        android:id="@+id/imageView8"
        android:layout_margin="40dp"
        android:src="@drawable/thumbsup"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />




    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Congratulations on completing your order\nPlease rate your experience to proceed further."
        android:id="@+id/textView9"
        android:textColor="#000000"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="20dp"/>


    <RatingBar
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/ratingBar"
      android:layout_gravity="center" />

   <EditText
        android:layout_width="match_parent"
        android:layout_height="0dp"
       android:layout_weight="1"
        android:hint="Leave a comment"
       android:layout_margin="20dp"
        android:id="@+id/feedbackTxt"
        android:layout_gravity="center" />

  <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
      android:layout_weight="1"
      android:layout_margin="20dp"
        android:text="Submit"
        android:drawableLeft="@drawable/rateepng"
        android:layout_marginLeft="20dp"
        android:id="@+id/ratebtn"
        android:background="@drawable/theme_button"
        android:textColor="#ffffff"
       android:layout_gravity="center" />


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/skip"
    android:layout_weight="1">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="SKIP"
        android:textColor="#000000"
        android:layout_centerInParent="true"/>

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

尝试从Xml中删除权重,看看它是否有助于更快地加载您的活动。