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 メソッドで宣言する必要がありますか? それともわかりません...それはソフトウェアアクセラレーションに関するものですか?すべての答えに Thx :)

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 に答える