안드로이드 개발 질문/답변
(글 수 45,052)
원래 버튼이 한개인데.... 특별한경우에 버튼이 두개가 나오게 되게 하고싶은데요
xml로 만들어놓을 경우 버튼두개만들어놓으면 하나를 안쓴다고 해도 버튼이 나타 나잖아요?
그래서 버튼이 있는 부분만 따로 버튼 하나짜리 xml, 버튼 두개짜리 xml로 만들어서 main.xml에 필요할때 겹치고싶은데
어떻게 해야되나요?
아니면 다른 좋은 방법 있으면 좀 가르쳐주세요 alterdialog로 하려했지만 화면 중앙에 나오고 뒷배경이 흐려지는 특성상 사용할수가 없어요...
2010.07.01 02:32:12
2. 만약 버턴 사이즈가 각각 틀리다면
이것도 구현하기 나름이겠지만.
main.xml에서
Layout을 2개 만드시고 Layout자체를 위에 옵션으로 토글처럼 사용하시면 끝날것 같내요
// 숨겨지는 Layout
<LinearLayout android:id="@+id/LY1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<Button android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout >
// 보여지는 Layout
<LinearLayout android:id="@+id/LY2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible">
<Button android:id="@+id/B2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/B3"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout >
이것도 구현하기 나름이겠지만.
main.xml에서
Layout을 2개 만드시고 Layout자체를 위에 옵션으로 토글처럼 사용하시면 끝날것 같내요
// 숨겨지는 Layout
<LinearLayout android:id="@+id/LY1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<Button android:id="@+id/test"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout >
// 보여지는 Layout
<LinearLayout android:id="@+id/LY2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="visible">
<Button android:id="@+id/B2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/B3"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout >
2010.07.01 02:36:43
자바 소스단에서 아래와 같이 다시 보여지고 숨기는 것을 바꾸시면 될겁니다.
Button TEST = (Button)findViewById(R.id.bottom_btn); //이놈은 따로 선언하세요 귀찮아서 위에 xml에는 없습니다.
LinearLayout LY1 = (LinearLayout)findViewById(R.id.LY1);
LinearLayout LY2 = (LinearLayout)findViewById(R.id.LY2);
TEST.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LY1 .setVisibility(View.VISIBLE); //보이기
LY2 .setVisibility(View.GONE); //숨기기
}
});
Button TEST = (Button)findViewById(R.id.bottom_btn); //이놈은 따로 선언하세요 귀찮아서 위에 xml에는 없습니다.
LinearLayout LY1 = (LinearLayout)findViewById(R.id.LY1);
LinearLayout LY2 = (LinearLayout)findViewById(R.id.LY2);
TEST.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LY1 .setVisibility(View.VISIBLE); //보이기
LY2 .setVisibility(View.GONE); //숨기기
}
});
그럴경우 구현하기 나름일겁니다.
xml을 2개까지 만드실 필요는 없습니다.
main.xml 이라는 기준으로 설명 하겠습니다.
1. main.xml에
Layout을 선언 하시고 Layout안에 버턴 2개를 선언해주세요
그리고 하나는 xml 속성을 android:visibility="gone" 주시면 보이지 않게 합니다.
(그리고 보이게 하고 싶으면 소스단에서 보여 주세요)
그런데 님께서 어떤것을 원하는지 정확히 몰라서 visibility="gone" 속성값을 설명을 드려야 할것 같내여
- "gone" 는 버턴을 숨겨버리는 역활을 합니다. 대신 버턴뒤에 뭔가가 선언이 되어있었다면
gone으로 선언 한 놈의 자리를 밀고 뒤에 배치된놈이 그자리에 보여집니다. (말이 어렵내여)
- "visible"는 숨겨진놈을 다시 보이게 합니다.
- "invisible" 1번의 설명에서는 숨기고자 하는 위젯 위치를 바로 뒷놈에게 넘기지만
이놈은 자리를 그대로 유지하면서 숨겨주는 역활을 합니다. (어미 외이렇게 말이 어려운지)