2013-01-19 2 views
0

안녕하세요. 시야를 설정하는 데 문제가 있습니다. 내 xml 파일 :Android 요소의 가시성이 제대로 작동하지 않습니다.

<?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 초 후 apear해야한다는 것입니다 (10500)하지만 그렇지 않습니다. 시간이 1 초 (999) 미만으로 설정되면 정상적으로 작동합니다. 또한 비디오 뷰를 버리면 "Kn8s"요소가 시간이 지나면 표시됩니다. 왜 효과가 없습니까? 그것은 onStart 메서드로 선언되어야합니까? 또는 나는 모른다. .. 그것은 소프트웨어 가속에 관한 것이냐? 모든 대답 :

+0

포인트를 얻었습니까 – Janmejoy

답변

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); 

이 Janmejoy의 대답에

new Handler().postDelayed(new Runnable() { 
      public void run() { 
       productions.setVisibility(View.VISIBLE); 
      } 
     }, 10500); 
+0

예, 감사합니다. 나는 그것을 시도했지만 문제를 해결하지 못했다. 그러나 나는 그런 식으로 코딩 할 수 있다는 것을 아는 것이 좋다. :) 그리고 코드는 더 멋지게 보인다! – NightKn8

0

헤이 덕분에 위의 코드를 교체 I가 해결책을 발견했다 내 문제! 이유는 "사라"

<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" 
    /> 

그럼 누군가가 말해 줄 수 "보이지 않는"하지 않는 동안 작동!? :

에서
<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" 
    /> 

에 : 내가했던 일은 내 XML의이 부분을 변경하는 것입니다 주문에 따라가로 : https://stackoverflow.com/a/7348547/1873367 " View.GONE이보기는 보이지이며, 레이아웃 목적으로 어떤 공간을 차지하지 않는 View.INVISIBLE이보기는 눈에 보이지 않는,하지만 여전히 레이아웃 목적으로 공간을 차지 .." 그것이 그렇다면, 제 경우에는 중요하지 않습니다! 또는해야합니까?

관련 문제