2014-10-09 18 views
-1

我製作了類似於卡片刷卡的視圖(此佈局有點複雜)。我的抽屜佈局在除此之外的每個片段上都能正常工作(刷卡視圖)。當我在這個片段,當我嘗試打開抽屜佈局,然後它滯後(也在關閉時)。我經歷了SO上的各種鏈接,它只在選擇抽屜佈局項目後告訴我如何執行任務,但在我的情況下,它僅在開放時才落後。抽屜佈局在複雜視圖中滯後

這裏是我添加視圖在這使它複雜(我猜)

private void addView(ArrayList<String> drawableList, final SearchUserData searchUserData) { 
    windowWidth = mainBaseActivity.getWindowManager().getDefaultDisplay().getWidth(); 
    windowHeight = mainBaseActivity.getWindowManager().getDefaultDisplay().getHeight(); 

    screenCenterX = windowWidth/2; 
    screenCenterY = windowHeight/2; 
    xDistance = ((windowWidth-(windowWidth-120))/2)/2; 

    for (int i = 0; i < drawableList.size(); i++) { 

     final View myRelView = inflater.inflate(R.layout.custom_layout, null); 
     final ImageView m_image = (ImageView) myRelView.findViewById(R.id.sp_image); 
     m_topLayout = (RelativeLayout) myRelView.findViewById(R.id.sp_color); 
     txtViewUserNameAge = (TextView) myRelView.findViewById(R.id.txtViewUserNameAge); 

     //   final FrameLayout myRelView = new FrameLayout(mainBaseActivity); 
     myRelView 
     .setLayoutParams(new LayoutParams((windowWidth - 120), windowWidth-120)); 
     myRelView.setX((windowWidth-(windowWidth-120))/2); 
     myRelView.setY(windowWidth/3-90); 
     myRelView.setRotation(0); 
     myRelView.setTag(i); 
     m_image.setTag(i); 
     //   m_image.setImageDrawable(myImageList.get(i)); 
     ImageLoader.getInstance().displayImage(drawableList.get(i), m_image, options); 
     txtViewUserNameAge.setText(""+searchUserData.getData().get(i).getName()+", "+searchUserData.getData().get(i).getAge()); 
     frameLayouts.add(m_image); 
     viewlist.add(myRelView); 
     topLayoutlist.add(m_topLayout); 

     topMargin = myRelView.getTop(); 
     int imagePosition = drawableList.size() - 1; 
     //   
     //    if (i == imagePosition) { 
     //     myRelView.setLayoutParams(new LayoutParams((windowWidth - 120), windowWidth-120)); 
     //     myRelView.setX(xDistance + 40); 
     //     myRelView.setY(windowWidth/3-90); 
     // 
     //    } else if (i == imagePosition - 1) { 
     //     myRelView.setLayoutParams(new LayoutParams((windowWidth - 120), windowWidth-120)); 
     //     myRelView.setX(xDistance + 20); 
     //     myRelView.setY(windowWidth/3-90); 
     // 
     //    } 

     if (i == imagePosition) { 
      myRelView.setLayoutParams(new LayoutParams((windowWidth - 120), windowWidth-120)); 
      myRelView.setX(xDistance + 40); 
      myRelView.setY(windowWidth/3-90); 

     } else if (i == imagePosition - 1) { 
      myRelView.setLayoutParams(new LayoutParams((windowWidth - 120), windowWidth-120)); 
      myRelView.setX(xDistance + 20); 
      myRelView.setY(windowWidth/3-90); 

     } else { 
      myRelView.setLayoutParams(new LayoutParams((windowWidth - 120), windowWidth-120)); 
      myRelView.setX(xDistance); 
      myRelView.setY(windowWidth/3-90); 
     } 

parentView.addView(myRelView); 
} 

這裏運行時我的Java代碼是我的xml文件

<RelativeLayout 
    android:id="@+id/sp_color" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/blank_image" 
     android:scaleType="fitXY" /> 

    <ImageView 
     android:id="@+id/sp_image" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="@dimen/common_padding" 
     android:background="@drawable/baby1" 
     android:scaleType="fitXY" /> 

    <LinearLayout 
     android:id="@+id/bottomLayout" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/navigation_bar_height" 
     android:layout_alignParentBottom="true" 
     android:layout_margin="@dimen/common_padding" 
     android:background="#99000000" 
     android:gravity="center" > 

     <TextView 
      android:id="@+id/txtViewUserNameAge" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Jessica Alba, 26" 
      android:textColor="@android:color/white" 
      android:textSize="@dimen/normal_text_size" /> 
    </LinearLayout> 
</RelativeLayout> 

+1

你期望有人讀你的想法嗎?你沒有發佈任何關於你在代碼中實際做了什麼,只是結果與糟糕的性能問題...,並沒有,我沒有投票... – pskink 2014-10-09 09:40:19

+0

對不起,我的解釋方式,但我告訴這裏我是什麼我正面臨着。我在這裏還提到,我的觀點很複雜,在這裏顯示我的代碼沒有用:( – 2014-10-09 09:44:54

+0

沒問題,所以我只能說:我和你一起在你的痛苦中..堅強而勇敢...... – pskink 2014-10-09 09:49:04

回答

0

我解決了抽屜佈局的這個口吃問題。我只是把我的addView(....)方法放在AsyncTask中,現在它的工作很完美。

相關問題