2

I am showing and hiding views on a particular actions using some animation, I used LayoutTransition and it seems to work fine except one thing, while the animation is going, the background of some TextViews changes and reset to the default white background!!

Following is the code I am using to apply animation after hide/show.

mRightTransitioner = new LayoutTransition();
mRightTransitioner.setDuration(1000);
vg_rightContainer.setLayoutTransition(mRightTransitioner);

Edited: even without animation i tried, same problem, the background resets once view's position changes

Edited: here how i declared the views in the XML

<LinearLayout
        android:id="@+id/ll_req_reasonwrapper"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="10dp"
        android:baselineAligned="false"
        android:gravity="right"
        android:orientation="horizontal"
        android:visibility="gone" >

        <EditText
            android:id="@+id/et_req_reasons"
            android:layout_width="400dp"
            android:layout_height="match_parent"
            android:background="@drawable/comments_textbox"
            android:gravity="right|center_vertical"
            android:inputType="text"
            android:paddingRight="8dp" />

        <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:text="@string/str_req_preasons" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_req_timewrapper"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:baselineAligned="false"
        android:gravity="right"
        android:orientation="horizontal"
        android:visibility="gone" >

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

            <TextView
                android:id="@+id/ftv_req_endtime"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="@drawable/comments_textbox"
                android:freezesText="true"
                android:gravity="right|center_vertical"
                android:inputType="numberDecimal"
                android:paddingRight="8dp" />

            <TextView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:gravity="center_vertical"
                android:text="@string/str_req_endtime" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/ll_req_starttimewrapper"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="50dp" >

            <TextView
                android:id="@+id/ftv_req_starttime"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="@drawable/comments_textbox"
                android:freezesText="true"
                android:gravity="right|center_vertical"
                android:inputType="numberDecimal"
                android:paddingRight="8dp" />

            <TextView
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:gravity="center_vertical"
                android:text="@string/str_req_starttime" />
        </LinearLayout>
    </LinearLayout>

for instance: if i hide 'll_req_reasonwrapper', then the LinearLayout 'll_req_timewrapper' moves up, then the backgrounds of the textViews like 'ftv_req_starttime' becomes white!!

Please help.

mzyoussif
  • 21
  • 6

2 Answers2

0

Edited Answer: if your are using linear layout then if the child is not being displayed, it is not going to be laid out and not going to be the part of the measurements ( as it looks like ). I recommend to use the RelativeLayout.

You can try

android:background="@null"

for your buttons. if your are using some custom class for button then add

.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

for this specific views.

Attiq ur Rehman
  • 475
  • 1
  • 6
  • 21
  • thanks @Attiq but i need the background to stay before and after the animation, it is a drawable background – mzyoussif Mar 18 '14 at 12:27
  • I have edited my answer, have a review it. Hope it will help you – Attiq ur Rehman Mar 18 '14 at 12:39
  • i am using linear layout right, but the thing is i used it because i need once the view gets disappeared, the view belows it moves up and replace the disappeared view, and i noticed also that even without animation the background get disappeared too. – mzyoussif Mar 18 '14 at 12:48
  • k Mr.@Attiq i will try now, i hope too :)) – mzyoussif Mar 18 '14 at 12:54
  • unfortunately no Mr, i switched the container from linear to relative, same issue – mzyoussif Mar 18 '14 at 13:07
0

Need more code. The fact that disabling the LayoutTransition does not solve your issue, means that the animation is not the issue.

How do you reinstantiate child views or populate your view. Are you removing views with setVisibility(View.GONE) and then setting them back with setVisibility(View.VISIBLE)

OR

Are you removing childAt(i) and then dynamically adding custom views

I'm sorry I couldnt add a comment since I dont have the reputation for that but I think I am able to answer your question if you post more code.

  • Yes Exactly Bro animation is not the problem, and i am hiding by setVisiblity(View.GONE), the code no more than that, the thing is the background stays if the textview stayed in the same place after hiding/showing, but disappeared if it moves up or down (for instance if the textview above it became hidden it should move to up) – mzyoussif Mar 20 '14 at 05:18
  • i added example of coe in the question – mzyoussif Mar 20 '14 at 05:27
  • Hello. The xml is not much of help. Can you provide your GUI update method and any code that changes the backgrounds, hides and shows the views. – Joakim Sandqvist Mar 20 '14 at 10:00