Android的 - 隐藏浏览 [英] Android -- Hiding Views

查看:219
本文介绍了Android的 - 隐藏浏览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我做了一些环顾四周,我看看你都应该做到这一点,但对我来说,它只是不工作。

Okay, so I've done some looking around and I see how you are SUPPOSED to do it, but for me, it is just not working.

我需要能够设置一个RelativeLayout的的α都在XML和在code。对于我的XML,我有以下

I need to be able to set the alpha of a RelativeLayout both in XML and in 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>

我得到的错误:的包中发现的属性'阿尔法'无资源标识符'机器人'

此外,基于Android的文件,我应该能够调用 setAlpha(双)上的任何视图对象,但是当我尝试做一个RelativeLayout的这一呼吁它告诉我,这种方法没有定义该对象。

Also, based on the Android documentation, I should be able to call setAlpha(double) on any View object, but when I try to make that call on a RelativeLayout it tells me that this method is not defined for this object.

为什么我不能够控制在Android的一个RelativeLayout的对象的Alpha透明度?我失去了一些东西?谢谢!

Why am I not able to control the alpha transparency for a RelativeLayout object in Android? Am i missing something? Thanks!

更新

虽然使用visibility属性的作品,它$ P $从能够点击的ViewGroup pvents我。这对我来说很重要,因为我利用的ViewGroup的OnTouchListener。

Although using the visibility property works, it prevents me from be able to click on the ViewGroup. This is important for me because I am utilizing the OnTouchListener of the ViewGroup.

我所试图做的是有一个层,媒体控制,最初隐藏。当用户点击anywere在屏幕上,我想控制,以淡入,当他们点击屏幕,我再次想控制淡出。我有这部分已经工作。我使用的是ViewGroup中,坐在过顶我与OnTouchListener整个应用程序的连接,可确定它是否有或没有被触及。我的问题是,动画运行淡出控制后,它们重新出现。如果我使用@Hydrangea建议,我可以把它淡出,并立即可见。这给了我想要的效果,但随后的ViewGroup是不可点击,用户无法得到控制回来(或者消失,这取决于我们决定先做)。

What I am trying to do is to have a layer with media controls, initially hidden. when the user taps anywere on the screen, I want the controls to fade in and when they tap the screen again I want the controls to fade out. I have this part already working. I am using a viewgroup that sits over-top my entire application with an OnTouchListener attached that can determine if it has or hasn't been touched. My problem is that after the animation runs to fade out the controls, they re-appear. If I use @Hydrangea suggestion, I can have it fade out and immediately made invisible. This gives me the desired effect, but then the ViewGroup is unclickable and the user cannot get the controls to come back (or go away, depending on what we decide to do first).

我希望这是有道理的。

I hope this makes sense.

推荐答案

您需要使用一个奥飞动漫褪色的东西进出。这样可以保持你的触摸事件,您的布局。下面是一个例子

You'll want to use a alpha animation to fade things in and out. This will maintain your touch events for your layouts. Here's 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;
        }

    });
}

}

下面是附带的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>

这篇关于Android的 - 隐藏浏览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆