android - Why does the ProgressBar animation misbehave when adding it after the parent view has been laid out? -


i have activity button , linearlayout. every time button clicked, newly inflated view added linearlayout via addview(). added view single progressbar.

when adding new views after linearlayout has been laid out, progressbar animation behaves weirdly, doing part of spin. however, when adding new views before linearlayout has been laid out (in activity's oncreate()), of them behave normally.

why happen? there way fix problem? problem seems appear on android 5.x, works expected in newer versions. maybe it's platform bug, think rather simple use case, , provided there no info on internet, maybe it's doing wrong. it?

here code:

mainactivity.java

public class mainactivity extends appcompatactivity {      linearlayout mainlayout;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          mainlayout = (linearlayout) findviewbyid(r.id.main_layout);          //these 3 views display correct progressbar animation         (int = 0; < 3; i++) {             addelement();         }          findviewbyid(r.id.add_button).setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 //these views not display correct progressbar animation                 //(on android 5.0 or 5.1)                 addelement();             }         });     }      private void addelement() {         view childview = view.inflate(this, r.layout.test_element, null);         mainlayout.addview(childview);     } } 

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical">      <button         android:id="@+id/add_button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="add view" />      <linearlayout         android:id="@+id/main_layout"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical" /> </linearlayout> 

test_element.xml

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

here behavior right (the first 3 ones added before view laid out):

current app behavior

thanks!


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -