2016-07-28 9 views
0

私はDialogFragmentを作成しましたが、今はその中のScrollViewに問題があります。それはスクロールが非常に遅く、なぜ私が見つけることができません。 Androidスタジオで次の行を追加するようおすすめ:DialogFragment内のScrollViewが非常に遅い

android:baselineAligned="false" 

しかし、それはまったく役に立たなかった。

は、その後、私は2つのチャイルズ( - >相対 - ScrollView >リニア)の1を取り出し、パフォーマンスへの影響はありませんが、しかし、それは(すべてが明らかに親と一致するように設定されている場合、コンテンツをラップ)小さなスペースにすべてをつぶしました。したがって、RelativeLayoutは明らかにすべてを所定の位置に保持します。このレイアウトでのボタンの負荷があります

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:background="@drawable/main_bc" 
    android:weightSum="1" 
    android:layout_gravity="center" 
    android:layout_height="match_parent"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:baselineAligned="false" 
     android:layout_marginTop="50dp" 
     android:layout_marginBottom="45dp" 

     android:id="@+id/scrollView3" > 
     <RelativeLayout 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:baselineAligned="false" 
       android:weightSum="1" 
       android:layout_height="match_parent" > 

       <Button 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/back" 

        android:id="@+id/bShopBack" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/bettsoft" 

        android:id="@+id/bbTap" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/friends" 
        android:id="@+id/bb1" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/advert" 
        android:id="@+id/bb2" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/lottery" 
        android:id="@+id/bb3" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/elcar" 
        android:id="@+id/bb4" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/scomp" 
        android:id="@+id/bb5" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/mcomp" 
        android:id="@+id/bb6" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/lcomp" 
        android:id="@+id/bb7" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/trains" 
        android:id="@+id/bb8" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/electronics" 
        android:id="@+id/bb9" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/medres" 
        android:id="@+id/bb10" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/himp" 
        android:id="@+id/bb11" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/tvs" 
        android:id="@+id/bb12" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/shouse" 
        android:id="@+id/bb13" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/mobosdev" 
        android:id="@+id/bb14" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/envprot" 
        android:id="@+id/bb15" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/digcurr" 
        android:id="@+id/bb16" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/nano" 
        android:id="@+id/bb17" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/holopho" 
        android:id="@+id/bb18" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/timetrav" 
        android:id="@+id/bb19" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/comspatra" 
        android:id="@+id/bb20" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="113dp" 
        android:background="#800011FF" 
        android:layout_marginTop="5dp" 
        android:text="@string/spaele" 
        android:id="@+id/bb21" /> 

      </LinearLayout> 
     </RelativeLayout> 
    </ScrollView> 

</LinearLayout> 

:それでも、取り外しそれはパフォーマンスには影響を

はここに私のXMLファイルされていませんでした。しかし、それは実際問題ではありません。私はスクロールすることはほとんどない2番目のレイアウトを持っていますが、スピードはまだまだ遅いです...私のデバイスではなく、まったく新しいモデルです。また、起動前のテストではすべてのデバイスで検出されました。

対応するDialogFragmentクラス。

public class ShopDialog extends DialogFragment implements View.OnClickListener { 
    Context c; 
    Clicker cl; 
    /** 
    * Activity class reference to call more dialogs from this 
    * DialogFragment 
    */ 
    Game game; 

    public static ShopDialog newInstance() { 
     ShopDialog f = new ShopDialog(); 

     // Supply num input as an argument. 
     Bundle args = new Bundle(); 

     f.setArguments(args); 

     return f; 
    } 

    public void params(Context c, Clicker cl, Game game){ 
     this.c = c; 
     this.cl = cl; 
     this.game = game; 

    } 




    @Override 
    public void onCreate(Bundle sis){ 
     super.onCreate(sis); 
     //  setContentView(null); 

     int style, theme; 

     style = DialogFragment.STYLE_NO_FRAME; 
     theme = android.R.style.Theme_Holo_Dialog; 


     setStyle(style, theme); 

    } 

    private View v; 



    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View v = inflater.inflate(R.layout.shop, container, false); 
     this.v = v; 
     setButtons(); 
     return v; 
    } 





    private Button tap, back; 
    private Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20,b21; 

    private void setButtons(){ 
     tap = (Button) v.findViewById(R.id.bbTap); 
     back = (Button) v.findViewById(R.id.bShopBack); 

     b1 = (Button) v.findViewById(R.id.bb1); 
     b2 = (Button) v.findViewById(R.id.bb2); 
     b3 = (Button) v.findViewById(R.id.bb3); 
     b4 = (Button) v.findViewById(R.id.bb4); 
     b5 = (Button) v.findViewById(R.id.bb5); 
     b6 = (Button) v.findViewById(R.id.bb6); 
     b7 = (Button) v.findViewById(R.id.bb7); 
     b8 = (Button) v.findViewById(R.id.bb8); 
     b9 = (Button) v.findViewById(R.id.bb9); 
     b10 = (Button) v.findViewById(R.id.bb10); 
     b11 = (Button) v.findViewById(R.id.bb11); 
     b12 = (Button) v.findViewById(R.id.bb12); 
     b13 = (Button) v.findViewById(R.id.bb13); 
     b14 = (Button) v.findViewById(R.id.bb14); 
     b15 = (Button) v.findViewById(R.id.bb15); 
     b16 = (Button) v.findViewById(R.id.bb16); 
     b17 = (Button) v.findViewById(R.id.bb17); 
     b18 = (Button) v.findViewById(R.id.bb18); 
     b19 = (Button) v.findViewById(R.id.bb19); 
     b20 = (Button) v.findViewById(R.id.bb20); 
     b21 = (Button) v.findViewById(R.id.bb21); 

     tap.setOnClickListener(this); 
     back.setOnClickListener(this); 

     b1.setOnClickListener(this); 
     b2.setOnClickListener(this); 
     b3.setOnClickListener(this); 
     b4.setOnClickListener(this); 
     b5.setOnClickListener(this); 
     b6.setOnClickListener(this); 
     b7.setOnClickListener(this); 
     b8.setOnClickListener(this); 
     b9.setOnClickListener(this); 
     b10.setOnClickListener(this); 
     b11.setOnClickListener(this); 
     b12.setOnClickListener(this); 
     b13.setOnClickListener(this); 
     b14.setOnClickListener(this); 
     b15.setOnClickListener(this); 
     b16.setOnClickListener(this); 
     b17.setOnClickListener(this); 
     b18.setOnClickListener(this); 
     b19.setOnClickListener(this); 
     b20.setOnClickListener(this); 
     b21.setOnClickListener(this); 

    } 


    @Override 
    public void onClick(View v) { 
     switch (v.getId()) { 
      case R.id.bShopBack: 
       dismiss(); 
       break; 
      case R.id.bbTap: 
       FragmentTransaction ft99 = getFragmentManager().beginTransaction(); 
       Fragment prev99 = getFragmentManager().findFragmentByTag("sdialog99"); 
       if (prev99 != null) { 
        ft99.remove(prev99); 
       } 
       ft99.addToBackStack(null); 

       // Create and show the dialog. 
       TapUpDialog newFragment99 = TapUpDialog.newInstance(); 
       newFragment99.params(c,cl, game, cl.tap); 
       newFragment99.show(ft99, "sdialog99"); 
       break; 
      case R.id.bb1: 
       showItemDialog(cl.items[0], 0); 
       break; 
      case R.id.bb2: 
       showItemDialog(cl.items[1], 1); 
       break; 
      case R.id.bb3: 
       showItemDialog(cl.items[2], 2); 
       break; 
      case R.id.bb4: 
       showItemDialog(cl.items[3], 3); 
       break; 
      case R.id.bb5: 
       showItemDialog(cl.items[4], 4); 
       break; 
      case R.id.bb6: 
       showItemDialog(cl.items[5], 5); 
       break; 
      case R.id.bb7: 
       showItemDialog(cl.items[6], 6); 
       break; 
      case R.id.bb8: 
       showItemDialog(cl.items[7], 7); 
       break; 
      case R.id.bb9: 
       showItemDialog(cl.items[8], 8); 
       break; 
      case R.id.bb10: 
       showItemDialog(cl.items[9], 9); 
       break; 
      case R.id.bb11: 
       showItemDialog(cl.items[10], 10); 
       break; 
      case R.id.bb12: 
       showItemDialog(cl.items[11], 11); 
       break; 
      case R.id.bb13: 
       showItemDialog(cl.items[12], 12); 
       break; 
      case R.id.bb14: 
       showItemDialog(cl.items[13], 13); 
       break; 
      case R.id.bb15: 
       showItemDialog(cl.items[14], 14); 
       break; 
      case R.id.bb16: 
       showItemDialog(cl.items[15], 15); 
       break; 
      case R.id.bb17: 
       showItemDialog(cl.items[16], 16); 
       break; 
      case R.id.bb18: 
       showItemDialog(cl.items[17], 17); 
       break; 
      case R.id.bb19: 
       showItemDialog(cl.items[18], 18); 
       break; 
      case R.id.bb20: 
       showItemDialog(cl.items[19], 19); 
       break; 
      case R.id.bb21: 
       showItemDialog(cl.items[20], 20); 
       break; 



     } 

    } 

    private void showItemDialog(Item item, int id){ 
     FragmentTransaction ft2 = getFragmentManager().beginTransaction(); 
     Fragment prev2 = getFragmentManager().findFragmentByTag("sdialog"+id); 
     if (prev2 != null) { 
      ft2.remove(prev2); 
     } 
     ft2.addToBackStack(null); 

     // Create and show the dialog. 
     ItemUpDialog newFragment2 = ItemUpDialog.newInstance(); 
     newFragment2.params(c,cl, game, item); 
     newFragment2.show(ft2, "sdialog"+id); 


    } 

} 

私はこれを理解できません。何か案は?

+0

リストビューを使用すると良いでしょう – Chol

+0

スクロールが含まれていますか?それはボタンで動作しますか? – Zoe

+0

はいlistViewはスクロール・ビューです。ビューが各行で似ている場合は使用されます – Chol

答えて

0

スタイリングの問題を微調整しようとしているうちに、スタイリング実験としてバックグラウンドを一時的に削除して解決しました。パフォーマンスは再び非常に良いです。私はこの行を削除しました:

android:background="@drawable/main_bc" 

それを解決しました。私はそれがなぜそれを解決したのかは分かりませんが、スクロールは現在かなり正常です。それ以上の遅れはありません。背景を生の色にして解決しました。

関連する問題