无法禁用和启用LayoutTransition

时间:2015-01-20 11:02:57

标签: android android-listview

在我的ListView我通过LayoutTransition设置onCreate()。但是在转换结束后,我想禁用转换效果,因此我将其设置为endTransition()中的 null 。所以,问题是在我将其设置为null之后,当我想要刷新ListView时,我无法再次启用事件(我希望通过滚动,单击,拖动,展开来禁用动画更改效果)

这是我的代码

MainActivity.class

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


      setupListViewAnimation();

 }

 void setupListViewAnimation() {
        if (lt == null) {
            lt = new LayoutTransition();
            lt.enableTransitionType(LayoutTransition.CHANGING);
            lt.addTransitionListener(new LayoutTransition.TransitionListener() {
                @Override
                public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {

                }

                @Override
                public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {
                    list.setLayoutTransition(null);
                }
            });
        }
        list.setLayoutTransition(lt);

}


void onClick() {
   //before start to refresh listview
   setupListViewAnimation();

   //refresh listview
   ..............................
   ListView Refresh Logic Here...
   ..............................


}

1 个答案:

答案 0 :(得分:1)

回答我自己的问题

我找到了自己的答案。如果我要将我的LayoutTransition动画设置值设置为null,我可以在endTransition LayoutTransition.TransitionListener()下的 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupListViewAnimation(); } void setupListViewAnimation() { if (lt == null) { lt = new LayoutTransition(); lt.enableTransitionType(LayoutTransition.CHANGING); lt.addTransitionListener(new LayoutTransition.TransitionListener() { @Override public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { } @Override public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { //Change this line of code to below one transition.disableTransitionType(LayoutTransition.CHANGING); } }); } list.setLayoutTransition(lt); } void onClick() { //before start to refresh listview setupListViewAnimation(); //refresh listview .............................. ListView Refresh Logic Here... .............................. } 下将其停用,例如下面修复的问题

{{1}}