2016-11-26 154 views
0

一个按钮,当我在我的移动(华为G8)在垂直视图它需要像5秒在我的应用程序点击任何这4个按钮的非常缓慢性能当我点击我的Android应用

还测试它它离开暗点在按钮秒或2 在水平视图它工作更快

在仿真器也能正常工作

Java文件

package com.example.kemo.videoplayer; 

import android.content.Context; 
import android.net.Uri; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.content.Intent; 
import android.widget.Button; 
import android.widget.ImageButton; 

public class Home extends AppCompatActivity { 

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

    final ImageButton facebook1 = (ImageButton)  findViewById(R.id.imageButton); 
    facebook1.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      // your handler code here image 1 
      Intent browserIntent = new Intent(Intent.ACTION_VIEW,  Uri.parse("http://www.facebook.com")); 
      startActivity(browserIntent); 
     } 
    }); 
    final ImageButton youtube1 = (ImageButton)  findViewById(R.id.imageButton2); 
    youtube1.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // your handler code here image 1 
      Intent browserIntent = new Intent(Intent.ACTION_VIEW,  Uri.parse("http://www.youtube.com")); 
      startActivity(browserIntent); 
     } 
    }); 


    final Button button = (Button) findViewById(R.id.btnabout); 
    button.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // your handler code here 
      Intent intent = new Intent(getBaseContext(), About.class); 
      startActivity(intent); 
     } 
    }); 

    final Button button1 = (Button) findViewById(R.id.btnaikido); 
    button1.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // your handler code here 
      Intent intent = new Intent(getBaseContext(), Aikido.class); 
      startActivity(intent); 
     } 
    }); 

    final Button button2 = (Button) findViewById(R.id.btnv); 
    button2.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // your handler code here 
      Intent intent = new Intent(getBaseContext(),  MainActivity.class); 
      startActivity(intent); 
     } 
    }); 

    final Button button3 = (Button) findViewById(R.id.btnpic); 
    button3.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // your handler code here 
      Intent intent = new Intent(getBaseContext(), Gview.class); 
      startActivity(intent); 
     } 
    }); 

} 


} 

XML文件

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 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"> 

<LinearLayout 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/activity_home" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     tools:context="com.example.kemo.videoplayer.Home"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:id="@+id/imageView3" 
      android:layout_height="140dp" 
      android:scaleType="fitXY" 
      android:background="@drawable/aikidobanner" /> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/btnabout" 
      android:layout_margin="5dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:id="@+id/btnaikido" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:text="@string/aikido" /> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/btnaikido" 
      android:layout_margin="5dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:id="@+id/btnv" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:text="@string/videos" /> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/btnv" 
      android:layout_margin="5dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:id="@+id/btnpic" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:text="@string/gallery" /> 

     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/btnabout" 
      android:text="@string/about" 
      android:layout_below="@+id/imageView3" 
      android:layout_margin="5dp" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <ImageButton 
      android:id="@+id/imageButton" 
      app:srcCompat="@drawable/facebook" 
      android:layout_width="120dp" 
      android:layout_height="60dp" 
      android:scaleType="fitXY" 
      android:layout_marginTop="10dp" 
      android:layout_marginRight="25dp" 
      android:layout_marginLeft="50dp" 

      android:background="@android:color/transparent" /> 

     <ImageButton 
      android:id="@+id/imageButton2" 
      app:srcCompat="@drawable/youtube" 
      android:layout_width="120dp" 
      android:layout_height="60dp" 
      android:scaleType="fitXY" 
      android:layout_marginTop="10dp" 
      android:layout_marginLeft="25dp" 
      android:layout_marginRight="50dp" 
      android:background="@android:color/transparent" /> 
    </LinearLayout> 

</LinearLayout> 
</ScrollView> 
+0

建议:让你的活动实现OnClickListener http://stackoverflow.com/a/30142323/2308683 –

回答

0

很难知道肯定没有看到该应用程序的其余部分,但是这听起来像你正在推出新的活动很可能在做的工作太多了onCreate方法,或者在启动过程中在UI线程上执行某些其他方法中的重量级权重。

从你展示的代码中,我认为它不太可能是你的主页活动中的任何东西,除非该活动在它的UI线程中发生了一些密集的事情。

+0

等活动不仅具有PIC和文字 –

0

从显示的代码中找不到任何明显的错误。所以如果没有更多的其他代码存在,问题依然存在,我建议你应该通过一个消除过程来找到它。例如,删除onCreate中的所有侦听器并添加一个,然后继续尝试。

+0

我删除了所有与只保留一个,但还是一样的慢 还有其他活动已只有图片和文字 –

+0

1也许应该尝试用空的XML替换你的内容视图。 2检查你的记忆,通常一个空的项目将占用16M左右。 3转储你的记忆,找出导致你的问题的原因。 – machinezhou