在按钮下可绘制动画

伯大尼

我已经搜索了堆栈溢出问题,但是仍然遇到这个问题。

我想Button在我的应用程序上显示,并使用AnimationDrawable作为背景。我遵循了Android开发人员页面(http://developer.android.com/guide/topics/graphics/drawable-animation.html)并能够使动画正常工作。但是,我的按钮是完全隐藏的。用户仍然可以单击它,但是背景动画会在视觉上隐藏它,就像没有按钮一样。

我已经尝试过setAlpha,但是将其应用于我的“ AnimationDrawable”会使我的Drawable“胶卷”中的3张图像模糊此外,屏幕从黑色开始,需要很长时间才能逐渐达到设置的不透明度。乍一看,这是一个内存问题,但截至目前,我的应用程序只是一个Activity带有A的应用程序Button而导致了另一个问题Activity

有谁知道如何让我Button出现在我的身上AnimationDrawable还是有人有setAlpha放慢动画速度的经验

这是我的代码供参考:

public class Main extends Activity {
Button start;
Intent intent= new Intent();
ImageView background;
AnimationDrawable animation;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    background= (ImageView) findViewById(R.id.imagehost);
    background.setBackgroundResource(R.drawable.anim);
    animation= (AnimationDrawable) background.getBackground();


    start= (Button) findViewById(R.id.start);

    start.setOnClickListener(new OnClickListener(){
        ...


} //end of onCreate

@Override
public void onWindowFocusChanged(boolean hasFocus){
    super.onWindowFocusChanged(hasFocus);
    animation.start();
    //animation.setAlpha(50); //doesn't help

}//end of onWindowFocusChanged

编辑

布局xml(main.xml)代码:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/start"
        android:textSize="40sp" />

    <ImageView
        android:id="@+id/imagehost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="58dp" />

animationdrawable.xml:

<?xml version="1.0" encoding="utf-8"?>

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/bgnd1" 
    android:duration="600" />
<item android:drawable="@drawable/bgnd2" 
    android:duration="600" />
<item android:drawable="@drawable/bgnd3"
     android:duration="600" />   


</animation-list>
caiocpricci2

互换位置<Button><ImageView>稍后在中添加的元素RelativeLayout,每个元素的z-index由添加到容器的顺序确定。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >     

<ImageView
    android:id="@+id/imagehost"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="58dp" />  
<Button
    android:id="@+id/start"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/start"
    android:textSize="40sp" />

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章