Android – Hide view
Well, so I did some looking around and I saw how you supported it, but for me, it just didn't work
I need alpha that can set relativelayout in XML and code. For my XML, I have the following
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/player_controls"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:alpha="0.0">
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/player_controls_touch_me"
>
</RelativeLayout>
</RelativeLayout>
I received an error: the resource identifier of attribute 'alpha' cannot be found in the 'Android' package
In addition, based on Android documentation, I should be able to call setalpha (double) on any view object, but when I try to call on relativelayout, it tells me that this method is not defined for this object
Why can't I control the alpha transparency of relativelayout objects in Android? Did I miss anything? thank you!
to update
Although the visibility property works, it prevents me from clicking ViewGroup. This is important to me because I am using the ontouchlistener of ViewGroup
What I want to do is have a layer with a media control, which is initially hidden. When users click on anything on the screen, I want the control to fade in, and when they click on the screen again, I want the control to fade out. I have this part already working. I am using a view group, which is located on top of my entire application and comes with an ontouchlistener, I can determine whether it has been touched. My problem is that after the animation runs and fades out the control, they will reappear. If I use @ Hydrangea's suggestion, I can make it fade out and become invisible immediately. This gives me the effect I want, but ViewGroup is not clickable, and users can't make the control return (or disappear, depending on what we decide to do first)
I hope this makes sense
resolvent:
You will want to use alpha animation to fade in and out. This will maintain the touch event of your layout. This is an example
public class Main extends Activity {
/** Called when the activity is first created. */
private boolean mShowing = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.textview).setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
if(mShowing){
Animation animation = new AlphaAnimation(1.0f, 0.0f);
animation.setFillAfter(true);
arg0.startAnimation(animation);
} else {
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setFillAfter(true);
arg0.startAnimation(animation);
}
mShowing = !mShowing;
}
});
}
}
This is the attached XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:clickable="true"
/>
</LinearLayout>