防止视图无效全视图

时间:2015-09-18 08:34:37

标签: android

希望你有一个愉快的一天,有一个问题,我坚持,由于我需要一个字幕TextView但RTL语言,因为正常的android选框无法这样做,我确实把textview放入Horizo​​ntalScrollView < / p>

  <HorizontalScrollView 
                      android:layout_height="wrap_content"
                      android:layout_width="match_parent"
                      android:id="@+id/hs"
                      android:scrollbars="none"
                      android:layout_alignParentBottom="true"
                      >

                  <TextView 
    android:id="@+id/moving_tv"
    android:text="                                                                        Your SubTitle ...                                                                                         "
    android:singleLine="true" 
    android:layout_gravity="bottom"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:textColor="@color/color_white"
    android:background="@color/color_black"
    android:fadingEdge="horizontal"
    android:scrollHorizontally="true"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
                      />

    </HorizontalScrollView>

我在这样的Timer()中骂它:

  task = new TimerTask() {

                    @Override
                    public void run() {

                        if(hs.getScrollX() == 0){

                            hs.scrollTo((hs.getChildAt(0).getMeasuredWidth()- windowSize),0);
                            return;
                        }

                        hs.smoothScrollBy(-1,0);




                    }
                };



    }

    timer.scheduleAtFixedRate(task, 0, 50);

问题是,每当任务运行时,视图滚动它就会调用自己的InvalidateChildInParent()和ViewGroup中的所有Layouts到root,所以我的整个视图都刷新并调用DispatchDraw(),Draw()和OnDraw()一次20次!!!电池,它似乎是性能和电池的毒药。有没有办法阻止ScrollView刷新其父母?非常感谢

0 个答案:

没有答案