2016-11-26 151 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