3

2 つの重なり合うレイアウトの滑らかさに関して、アプリで問題が発生しました。ある種のスライド メニュー (Facebook や YouTube など) を作成しました。このメニューには 2 つのレイアウトが含まれています。メイン レイアウトはデータを表示し、その下にメニュー レイアウトを含みます。次に、メニュー レイアウト自体、カスタム行レイアウトを使用した通常の ListView です。

主要:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<include
        android:id="@+id/menu_list"
        layout="@layout/menu_list"/>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/news_content"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#FFF"
              android:orientation="vertical">
    <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

 </LinearLayout>

 <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <ProgressBar
            android:id="@+id/NewsProgressBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:visibility="gone"
            style="@android:style/Widget.Holo.Light.ProgressBar.Large"/>

 </LinearLayout>

</RelativeLayout>

メニュー:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="250dip"
          android:layout_height="fill_parent"
          android:orientation="vertical"
          android:background="@drawable/ic_sidebar_bg">

<RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="wrap_content">

    <ImageView
            android:alpha="0.8"
            android:layout_height="40dp"
            android:layout_width="match_parent"
            android:background="#222222"/>

    <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="12dip"
            android:textSize="14dp"
            android:textColor="#666"
            android:text="@string/menu_cat_main"/>

    <ImageView
            android:layout_height="1dp"
            android:layout_marginTop="40dp"
            android:layout_width="match_parent"
            android:background="#666666"/>

</RelativeLayout>

<ListView
        android:id="@+id/mainMenuList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

このオーバーラップにより、ListViews がひどく遅れることをすでに認識しています。私が行ったのは、メニューに「visibility:gone」を含めることでした。これにより、ListViews が完全に正常に動作します。しかし、コンテンツを横にスライドさせようとすると、インクルード (メニュー) が再び表示され、スライドはスムーズではありません。ただし、この外観上の問題を除けば、メニューは YouTube のものとまったく同じように機能します。

次のコードに関して明確にするために: viewContent (View) には、コンテンツを含む LinearLayout が含まれますtouched) isMenuScrolled (bool) メニューがスライドアウトされるかどうかにかかわらず

タッチ イベントのコードは次のとおりです。

public boolean dispatchTouchEvent(MotionEvent touchevent) {

    switch (touchevent.getAction()) {
        case MotionEvent.ACTION_MOVE:

            if (canSlide) {
                if (touchevent.getX() < viewMenu.getWidth()) {
                    viewContent.setX(touchevent.getX());
                } else if (touchevent.getX() < 0) {
                    viewContent.setX(0);
                } else if (touchevent.getX() > viewMenu.getWidth()) {
                    viewContent.setX(viewMenu.getWidth());
                }

                viewContent.setEnabled(false);
            }
            return true;

        case MotionEvent.ACTION_DOWN:

            if (touchevent.getY() > 200 && touchevent.getX() < 50 && !isMenuScrolled) {
                viewMenu.setVisibility(View.VISIBLE);
                touchStart = touchevent.getX();
                canSlide = true;
            } else if (touchevent.getY() > 200 && touchevent.getX() > viewMenu.getWidth() && isMenuScrolled) {
                viewMenu.setVisibility(View.VISIBLE);
                touchStart = touchevent.getX();
                canSlide = true;
            } else {
                canSlide = false;
            }
            return true;

        case MotionEvent.ACTION_UP:

            if (viewContent.getX() != 0 || viewContent.getX() != viewMenu.getWidth()) {
                if (viewContent.getX() < touchStart) {
                    ObjectAnimator transAnimation = ObjectAnimator.ofFloat(viewContent, "x", viewContent.getX(), 0);

                    transAnimation.addListener(new Animator.AnimatorListener() {

                        @Override
                        public void onAnimationStart(Animator animator) {
                            viewContent.setEnabled(false);
                            isMenuScrolled = false;
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            viewMenu.setVisibility(View.GONE);
                            viewContent.setEnabled(true);
                        }

                        @Override
                        public void onAnimationCancel(Animator animator) {
                            // nothing
                        }

                        @Override
                        public void onAnimationRepeat(Animator animator) {
                            // nothing
                        }

                    });

                    transAnimation.setDuration(300);
                    transAnimation.start();

                } else if (viewContent.getX() > touchStart) {
                    ObjectAnimator transAnimation = ObjectAnimator.ofFloat(viewContent, "x", viewContent.getX(), viewMenu.getWidth());

                    transAnimation.addListener(new Animator.AnimatorListener() {

                        @Override
                        public void onAnimationStart(Animator animator) {
                            viewContent.setEnabled(false);
                            isMenuScrolled = true;
                        }

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            viewContent.setEnabled(true);
                        }

                        @Override
                        public void onAnimationCancel(Animator animator) {
                            // nothing
                        }

                        @Override
                        public void onAnimationRepeat(Animator animator) {
                            // nothing
                        }

                    });

                    transAnimation.setDuration(300);
                    transAnimation.start();
                }
            }
            return true;
    }

    return true;
}

この問題を解決して、スクロールをもう少しスムーズにするにはどうすればよいですか? 最後に、メニューのスクロール中にコンテンツを無効にする最良の方法は何ですか? viewContent.setEnabled が正常に機能していません。

BIG よろしくお願いします!

4

1 に答える 1

0

試す:

android:hardwareAccelerated="true"マニフェストの application タグの下に追加します。

と:myViewContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null);

これは、環境によってはよりスムーズになる可能性があります。運を試してみてください。

于 2016-05-04T09:43:01.410 に答える