Android– 隐藏视图

Android– 隐藏视图,第1张

概述好吧,所以我做了一些环顾四周,我看到你是如何支持的,但对我来说,它只是不起作用.我需要能够在XML和代码中设置RelativeLayout的alpha.对于我的XML,我有以下内容<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apkes/andr

好吧,所以我做了一些环顾四周,我看到你是如何支持的,但对我来说,它只是不起作用.

我需要能够在XML和代码中设置relativeLayout的Alpha.对于我的XML,我有以下内容

<?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’包中找不到属性’Alpha’的资源标识符

此外,基于AndroID文档,我应该能够在任何VIEw对象上调用setAlpha(double),但是当我尝试在relativeLayout上进行调用时,它告诉我没有为此对象定义此方法.

为什么我无法在AndroID中控制relativeLayout对象的Alpha透明度?我错过了什么吗?谢谢!

更新

虽然使用visibility属性可以工作,但它阻止我能够单击VIEwGroup.这对我很重要,因为我正在使用VIEwGroup的OntouchListener.

我想要做的是拥有一个带有媒体控件的图层,最初是隐藏的.当用户点击屏幕上的任何内容时,我希望控件淡入,当他们再次点击屏幕时,我希望控件淡出.我有这个部分已经工作了.我正在使用一个视图组,该视图组位于我的整个应用程序之上,并附带一个OntouchListener,可以确定它是否已被触及.我的问题是,在动画运行淡出控件后,它们会重新出现.如果我使用@Hydrangea建议,我可以让它淡出并立即变得不可见.这给了我想要的效果,但是VIEwGroup是不可点击的,用户无法让控件返回(或者消失,取决于我们先决定做什么).

我希望这是有道理的.

解决方法:

你会想要使用Alpha动画来淡入淡出.这将保持您的布局的触摸事件.这是一个例子

public class Main extends Activity {/** Called when the activity is first created. */private boolean mShowing = false;@OverrIDepublic 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 – 隐藏视图全部内容,希望文章能够帮你解决Android – 隐藏视图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1120349.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存