2011-10-02 7 views

답변

0

보기에 visibility 특성을 사용하여 표시 여부를 제어 할 수 있습니다. 여기 당신이 찾고있는 것을할만한 작은 예제가 있습니다.

주요 Activity

:

public class DynamicLayoutTestActivity extends Activity { 
    private ToggleButton toggleButton; 
    private View possiblyHiddenView; 

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

     toggleButton = (ToggleButton) findViewById(R.id.toggleButton); 
     possiblyHiddenView = (View) findViewById(R.id.possiblyHiddenView); 

     toggleButton.setOnCheckedChangeListener(toggleButtonOnCheckedChangeListener); 
    } 

    private final CompoundButton.OnCheckedChangeListener toggleButtonOnCheckedChangeListener 
      = new CompoundButton.OnCheckedChangeListener() { 
     @Override 
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
      if (isChecked) { 
       possiblyHiddenView.setVisibility(View.VISIBLE); 
      } else { 
       possiblyHiddenView.setVisibility(View.INVISIBLE); 
      } 
     } 
    }; 
} 

레이아웃 파일, main.xml :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
> 
    <ToggleButton 
     android:id="@+id/toggleButton" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textOff="Show" 
     android:textOn="Hide" /> 
    <LinearLayout 
     android:id="@+id/possiblyHiddenView" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:visibility="invisible" 
    > 
     <TextView 
      android:text="Stuff that could be hidden." 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
</LinearLayout> 

당신이 어떤 공간 사용의 가시성 gone 대신 invisible을 차지하기 위해 숨겨진보기를 원하지 않는 경우.

희망이 도움이됩니다.

+0

defintly는 도움을 주지만 도움이 될 때 다른보기의 배치와 함께 계속 표시됩니다. 내가 정말로 원했던 것은 기존 구성 요소 위에 표시되고 필요하지 않을 때 사라질 것입니다. – LostPuppy

+0

대화 상자와 같은 뜻입니까? –

+0

네 종류가 있지만 그 안에 컨트롤이 있어야합니다. 즉, 클릭 또는 수락 할 수있는 버튼을 의미 할 수 있습니다. – LostPuppy

0

Android 3.0 이상을 개발중인 경우 fragments을 확인하십시오.

+0

아니요. 안드로이드 2.2를 개발 중입니다. – LostPuppy

관련 문제