• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android PopupWindow performance issues

Espectro

Lurker
Nov 22, 2014
1
0
We are very close to production with our app, but are having some really strange and annoying performance issues when using the PopupWindow in Android. As soon as it is open, scrolling simply slooooows down and is extremely jerky. If I turn off hardware acceleration in the manifest, the problem almost disappears - unfortunately everything else in the app renders slowly in software mode so that is not an option. I posted this on stackoverflow as well, but doesn't seem to get a response, so I'm hoping to get a more specified audience here ;-).

I have tried to turn off hardware accelleration on the popup container (layout) and also on the scrollview but it doesn't seem to be doing any difference: Do I need to specifically turn off hardware accelleration on all child-views as well to have any effect?

I have also tried to turn off transparency but it makes no difference neither.

The code for initiating the popupwindow is here:

Code:
final LayoutInflater inflater = (LayoutInflater) Fragment_matches.this.getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.layout_matches_popup,
            (ViewGroup) getActivity().findViewById(R.id.layoutmatchespopup));

    fillMatchPopupWindow(context, match, layout, inflater);

    Display display = getActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int fifthHeight = size.y/5;
    int height = size.y-fifthHeight;
    if(pwindo != null) //TODO SIZECALC
        {
        pwindo.dismiss();
        if(matchPopupTimer != null)
            matchPopupTimer.cancel();
        }
    pwindo = new PopupWindow(layout, width-20, height, true);
    pwindo.setAnimationStyle(R.style.AnimationPopup);
    pwindo.setBackgroundDrawable(new BitmapDrawable());
    pwindo.showAtLocation(layout, Gravity.TOP, 0, 140);



    ImageButton btnClose = (ImageButton) layout.findViewById(R.id.popup_close);
    btnClose.bringToFront();
    btnClose.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(pwindo != null)
                pwindo.dismiss();
        }
    });

fillMatchPopupWindow() is the function that fills the popupwindow with data.

The layoutfile is structured like this:

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutmatchespopup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/popupshape"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:paddingBottom="15dp"
>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"
    >
    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

        <TextView
            android:id="@+id/popup_favteammatch_header"
            style="@style/FontHeadlineCaps"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="@string/popup_favteammatch_header" >
            </TextView>

            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:layout_marginTop="2dp"
                >
             <ImageButton android:id="@+id/popup_close"
                    android:contentDescription="Close"
                    android:layout_height="32dp"
                    android:layout_width="32dp"
                    android:src="@drawable/popup_close_red"
                    android:scaleType="centerInside"
                    style="?android:attr/borderlessButtonStyle"
                    android:layout_margin="0px"
                    android:padding="0px"
                    ></ImageButton>
             </LinearLayout>
        </LinearLayout>

        .......

    </LinearLayout>
</LinearLayout>




<ScrollView
    android:id="@+id/detailsscrollview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollX="0px"
    android:scrollY="0px" 
    android:paddingLeft="5dp"
    android:paddingRight="5dp"        
    >          
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">          
        <RelativeLayout
            android:id="@+id/statistics"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >
            .......

       <RelativeLayout
                android:id="@+id/panelpreviousmatches"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:background="@drawable/roundedsquare"
                android:alpha="0.8"
                android:paddingTop="6dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:layout_marginBottom="15dp" >

                    <ListView
                        android:id="@+id/id_list_viewprevmatches"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingBottom="4dp"
                        android:paddingTop="4dp" />

            </RelativeLayout>

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

You guys have any ideas what I'm doing wrong or how I can disable hardware accelleration for the popupwindow but not for anything else. Also, when openeing and closing the popupwindow we run an animation - and this runs smooth as silk, so the jerky behavious is only visible when scrolling in the popupwindow. Also, I have other popupwindow which is coded in the same architecture, and those also struggle with jerky motion.

BR Michael
 
How complex of a scrollview is this popupwindow? I am wondering if its not related to the popupwindow but more on something else.. like loading images, handling cache, etc.

Another thing... you say that if you turn off hardware acceleration its smooth... is it feasible to just turn it off for that view alone? Code to do so is the following:

Code:
popupWindowView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones