-1

I made a view similar to tinder like Cards Swiping(this layout is little complex). My drawer layout is working perfectly on every fragment except this one(Swiping Card view). When i am on this fragment and when i try to open drawer layout then it lags(and also at the time of closing). I went through various links on SO which only tell about how to perform task after selecting drawer layout item but in my case it lags at the time of opening only.

Here is my java code where i am adding view at run time which making it complex(as i guess)

   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);
}

And here is my xml file

<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>

Avinash Kumar Pankaj
  • 1,700
  • 2
  • 18
  • 27
  • 1
    do you expect anyone to read your minds? you didn't posted anything about what you actually done in your code, just results with bad performance issues..., and no, i didn't down vote... – pskink Oct 09 '14 at 09:40
  • Sorry for my way of explanation but i told here what i am facing. I also mentioned here that my view is complex and it will be no use to showing my code here :( – Avinash Kumar Pankaj Oct 09 '14 at 09:44
  • ok so i can only say: i'm with you in your pain.. be strong and brave... – pskink Oct 09 '14 at 09:49

1 Answers1

0

I fixed this stuttering problem of drawer layout. i just put my addView(....) method in AsyncTask and now its working perfectly.

Avinash Kumar Pankaj
  • 1,700
  • 2
  • 18
  • 27