0

嗨,我在设置可见性时遇到了问题。我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    android:id="@+id/widget324"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/onbg"
    xmlns:android="http://schemas.android.com/apk/res/android"
>

<Button android:id="@+id/topBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
</Button>

<VideoView
    android:id="@+id/introvid"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
 </VideoView>   
<ImageView
    android:id="@+id/Kn8s"
    android:visibility="invisible"
    android:src="@drawable/kn8s"
    android:layout_width="430.50dp"
    android:layout_height="121.00dp"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginBottom="10.00dp"
    /> 
<ImageView

    android:id="@+id/introimage"
    android:src="@drawable/pcintro"
    android:layout_width="215.25dp"
    android:layout_height="197.00dp"
    android:layout_gravity="center"
    />

</FrameLayout>

我的 .java 文件是:

import (...)

public class Intro extends Activity {
    VideoView vid;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        overridePendingTransition(R.anim.fadein,R.anim.fadeout);
        setContentView(R.layout.intro);
        vid = (VideoView)findViewById(R.id.introvid);
        String urlpath = "android.resource://" + getPackageName() + "/" + R.raw.onbg;
vid.setVideoURI(Uri.parse(urlpath));
        vid.start();
        FrameLayout widget324 = (FrameLayout)findViewById(R.id.widget324);
        widget324.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                 if (event.getAction() == MotionEvent.ACTION_DOWN) {
                        Intent OnIntent = new Intent(Intro.this, On.class);
                        startActivity(OnIntent);
                        Intro.this.finish();
                // TODO Auto-generated method stub
                 }
                return true;
            }});    

        final MediaPlayer mpGo = MediaPlayer.create(this, R.raw.intro);
        mpGo.start();          

        final ImageView productions = (ImageView)findViewById(R.id.Kn8s);
        productions.postDelayed(new Runnable() {
                public void run() {
                    productions.findViewById(R.id.Kn8s).setVisibility(ImageView.VISIBLE);
                }
            }, 10500);

            new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                    Intent OnIntent = new Intent(Intro.this, On.class);
                    startActivity(OnIntent);
                    Intro.this.finish();
            }
    }, 12000);     
        }   }  

问题是这里称为“(R.id.Kn8s)”的元素应该在10,5秒(10500)后出现,但事实并非如此。我注意到当时间设置在 1 秒(999)以下时,它工作正常!还注意到,当我丢弃视频视图时,“Kn8s”元素在它应该出现的时间后变得可见!为什么它不起作用?应该声明onStart方法吗?或者我不知道...是关于软件加速的吗?感谢每个答案:)

4

2 回答 2

2

尝试更换:

 productions.findViewById(R.id.Kn8s).setVisibility(ImageView.VISIBLE);

productions.setVisibility(View.VISIBLE);

您已经在延迟之前初始化了产品,因此您不必在延迟之后再次初始化。

不知道我是怎么错过的,但这似乎是问题所在:

 productions.postDelayed(new Runnable() {
            public void run() {
                productions.findViewById(R.id.Kn8s).setVisibility(ImageView.VISIBLE);
            }
        }, 10500);

将上面的代码替换为

 new Handler().postDelayed(new Runnable() {
            public void run() {
                productions.setVisibility(View.VISIBLE);
            }
        }, 10500);
于 2013-01-19T11:33:12.063 回答
0

嘿,感谢 Janmejoy 的回答,我找到了解决问题的方法!我所要做的就是更改我的 xml 的这一部分:

<ImageView
    android:id="@+id/Kn8s"
    android:visibility="invisible"
    android:src="@drawable/kn8s"
    android:layout_width="430.50dp"
    android:layout_height="121.00dp"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginBottom="10.00dp"
    /> 

进入:

<ImageView
    android:id="@+id/Kn8s"
    android:visibility="gone"
    android:src="@drawable/kn8s"
    android:layout_width="430.50dp"
    android:layout_height="121.00dp"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginBottom="10.00dp"
    /> 

那么有人可以告诉我为什么“消失”有效而“隐形”无效!?根据: https ://stackoverflow.com/a/7348547/1873367“ View.GONE 这个视图是不可见的,它不占用任何空间用于布局。View.INVISIBLE 这个视图是不可见的,但它仍然占用用于布局目的的空间。“所以如果是这样的话,在我的情况下它应该没关系!还是应该?

于 2013-01-19T16:12:20.980 回答