2011-04-30 2 views
1

서버에 연결되어있을 때 이미지를 표시하고 싶습니다. (저는 SIP 응용 프로그램을 개발 중입니다). ... 명령어 기능에서 UI 변경

public void onRegistrationDone(String localProfileUri, long expiryTime) { 
         updateStatus("Registered to server."); 
         Log.d("SUCCEED","Registration DONE"); 
         setContentView(R.layout.connected); 
         } 

내가 연결하고 분리 할 때 이미지를 추가 한 후 원하는 : 나는이 (텍스트 뷰와 이미지로 만든 XML 파일 [connected.xml])를 만들어,하지만 FC를했습니다 이 문제를 어떻게 해결할 수 있습니까? 대단히 감사합니다.

편집 : XML :

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

<TextView 
    android:id="@+id/sipLabel" 
    android:textSize="20sp" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/> 

<ViewFlipper 
    android:id="@+id/flipper" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <RelativeLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 


    <ImageView android:id="@+id/disconnected" android:src="@drawable/disconnected" android:layout_below="@id/sipLabel" 
    android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="0.35" android:gravity="center" 
    /> 
    </RelativeLayout> 

    <RelativeLayout android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 


    <ImageView android:id="@+id/connected" android:src="@drawable/connected" android:layout_below="@id/sipLabel" 
    android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_weight="0.35" android:gravity="center" 
    /> 
    </RelativeLayout> 

</ViewFlipper> 
</RelativeLayout> 

답변

1

당신은 당신이 모든 것을 정리 한 것을 100 % 확신하지 않는 한 당신은 하나 개의 활동에 setContentView 여러 번 호출하지 않아야을 고정.
그런데도 사용자가 이상하게 보일 수 있습니다. 뒤로 버튼을 누르면 대기중인 내용이 표시되지 않지만 동일한 활동을 시작합니다. 가 ViewFlipper를 사용

그래서 당신은 오히려 약

  • 의 다른 부분을 숨길/ 쇼, 또는
  • 더 우아하고 쉬운 솔루션으로 전망 '가시성을 변경하는 생각해야한다.당신은 변경해야 할 경우,

    <ViewFlipper android:id="@+id/flipper" 
        android:layout_width="fill_parent" android:layout_height="fill_parent"> 
        <RelativeLayout android:layout_width="fill_parent" 
         android:layout_height="fill_parent"> 
         <!-- your first view comes here --> 
        </RelativeLayout> 
        <RelativeLayout android:layout_width="fill_parent" 
         android:layout_height="fill_parent"> 
         <!-- your second view comes here --> 
        </RelativeLayout> 
    </ViewFlipper> 
    

    하고 자바 코드 :
    는 레이아웃 XML에서 다음 줄을 넣어 : 여기에 업데이트 1

ViewFlipper의 샘플 사용입니다 보기, 당신은 씁니다 :

엑스트라 : 당신은 showNext 또는 showPrevious를 호출하기 전에, 당신이해야 할 모든 설정하여 flipperinout 애니메이션을 당신의 반전에 애니메이션을 적용 할 수 있습니다 :

Animation inAnimation = new TranslateAnimation(
     Animation.RELATIVE_TO_PARENT, +1.0f, 
     Animation.RELATIVE_TO_PARENT, 0.0f, 
     Animation.RELATIVE_TO_PARENT, 0.0f, 
     Animation.RELATIVE_TO_PARENT, 0.0f); 
inAnimation.setDuration(250); 
inAnimation.setInterpolator(new AccelerateInterpolator()); 

Animation outAnimation = new TranslateAnimation(
     Animation.RELATIVE_TO_PARENT, 0.0f, 
     Animation.RELATIVE_TO_PARENT, -1.0f, 
     Animation.RELATIVE_TO_PARENT, 0.0f, 
     Animation.RELATIVE_TO_PARENT, 0.0f); 
outAnimation.setDuration(250); 
outAnimation.setInterpolator(new AccelerateInterpolator()); 

flipper = (ViewFlipper)findViewById(R.id.flipper); 
flipper.setInAnimation(inAnimation); 
flipper.setOutAnimation(outAnimation); 
flipper.showNext(); 

업데이트 2 :

샘플 ViewFlipper을위한 전체 헤더 포함 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <TextView android:id="@+id/status_text" android:text="Status: " 
     android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
    <ViewFlipper android:id="@+id/flipper" android:layout_below="@id/status_text" 
     android:layout_width="fill_parent" android:layout_height="fill_parent"> 
     <RelativeLayout android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
      <!-- your first view comes here without the status TextView --> 
     </RelativeLayout> 
     <RelativeLayout android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
      <!-- your second view comes here --> 
     </RelativeLayout> 
    </ViewFlipper> 
</RelativeLayout> 
+0

@rekaszeru : 저는이 ViewFlipper를 정말 좋아합니다! 제가 따라 올 수있는 가이드를 들려 주시겠습니까? 고맙습니다. – androniennn

+0

'ViewFlipper'의 샘플 사용법은 내 업데이트를 참조하십시오. – rekaszeru

+0

@rekaszeru : 음,이 멋진 답변에 감사드립니다. 이 주석으로 두 번째 상대성을 편집하십시오! (두 번째가 아닌;)). – androniennn

0

아마 스레드 문제 : UI 변경이 활동의 ​​메인 루프 스레드에서 발생해야합니다. http://developer.android.com/reference/android/os/Handler.html보기 :

  1. 활동에 대한 처리기를 만듭니다.
  2. 등록이 완료되면 메시지 (http://developer.android.com/reference/android/os/Message.html)를 보냅니다.
  3. 처리기에서 해당 메시지를 받고 UI를 변경하십시오.

어떻게 작동하는지 알려주십시오.

편집 : 메시지의 링크

+0

하지만 rekaszeru가 말했듯이 나는 UI를 변경할 수 없습니다 전자 활동 ...? – androniennn