Any View ( TableRow included) can have a fade animation attached to it, but you need to be able to refer to your view in the code, so the line will need an identifier:
<TableRow android:id="@+id/my_row" android:layout_height="fill_parent" android:layout_gravity="bottom" android:layout_width="fill_parent" android:background="#BF000000"> <TextView android:id="@+id/topText" android:layout_height="wrap_content" android:textColor="#FFFFFF" android:textSize="19sp" android:background="#BF000000" android:layout_gravity="center_horizontal" android:text="@string/text_searchword" android:layout_width="fill_parent"> </TextView> </TableRow>
Now you can reference the line directly in your Java code somewhere (e.g. onCreate() maybe) like
View row = findViewById(R.id.my_row);
Notice I do not use it as a TableRow . You could, if you need to do something else with it, but in order to just adjust the visibility, leaving it as a view in order. Then just create a button click method as follows:
public void onClick(View v) { View row = findViewById(R.id.myrow); if(row.getVisibility() == View.VISIBLE) { row.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); row.setVisibility(View.INVISIBLE); } else { row.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); row.setVisibility(View.VISIBLE); } }
Fade in and Fade out are standard animations defined in the Android package, you do not need to create them yourself, just download them using AnimationUtils.loadAnimation() . In this example, pressing the same button simply switches between fading out and fading out, depending on whether the visibility is already visible.
Hope this helps!
source share