안규 공부방

Android > Layout - include 와 보이기 숨기기

등록일 : 2017-07-05 11:07 조회수 : 93,782

include 태그를 사용하여 layout 을 포함할 수 있습니다.

main.xml
 
	<?xml version="1.0" encoding="utf-8"?>
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
		android:layout_width="match_parent"
		android:layout_height="match_parent"
		android:orientation="vertical" >

	<TextView
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:text="hello" />

		 <include layout="@layout/actionbar_noti" /> 
	</LinearLayout>
위의 예제처럼 actionbar_noti.xml 파일을 include 한 내용 입니다.


actionbar_noti.xml
 
	<?xml version="1.0" encoding="utf-8"?>
	<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
		xmlns:tools="http://schemas.android.com/tools"
		 android:id="@+id/actionbar_notify_pannel" 
		style="@style/AppBaseTheme"
		android:layout_width="match_parent"
		android:layout_height="wrap_content"
		android:layout_marginLeft="100dp"
		android:layout_marginRight="20dp"
		android:background="@drawable/popup_background"
		android:orientation="vertical"
		android:paddingTop="10dp"
		android:visibility="gone" >
		  
		<TextView
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:layout_marginBottom="10dp"
			android:text="@string/notify"
			android:textSize="20sp" />
	   
		<TextView
			android:layout_width="match_parent"
			android:layout_height="wrap_content"
			android:layout_marginBottom="10dp"
			android:text="테스트"
			android:textSize="20sp"
			android:textStyle="bold" /> 
	</LinearLayout>
 위의 LinearLayout 의 ID 값은 actionbar_notify_pannel 입니다.

안드로이드에서 이 LinearLayout 을 보임/숨김처리를 할 수 있습니다.
 
	LinearLayout notiPannel;
   	notiPannel = (LinearLayout) findViewById(R.id.actionbar_notify_pannel);

	if ( showNotiPannel ){
		notiPannel.setVisibility(View.GONE);
		showNotiPannel = false;
	}else{
		notiPannel.setVisibility(View.VISIBLE);
		showNotiPannel = true;
	}


setVisibility 속성을 이용하면 됩니다.


layout.setVisibility(View.VISIBLE);
해당 뷰를 보여줌

layout.setVisibility(View.INVISIBLE);
해당 뷰를 안 보여줌(공간은 존재)

layout.setVisibility(View.GONE);
해당 뷰를 안 보여줌(공간마저 감춤)

INVISIBLE과 GONE의 차이는 공간을 보여주느냐 안 보여주느냐의 차이이다.

예를 들면 1 2 3 4 5 의 숫자가 있을때 3을 숨기려고 한다면

INVISIBLE은 1 2 " " 4  5 이런 식으로 3은 없지만 자리는 남아있고

GONE은 1 2 4 5 이런 식으로 3과 공간 모두 숨기게 된다.
 
※ 혹시 도움이 되셨다면 댓글에 한마디 남겨주세요!
작성자   비밀번호
자동글 방지     (자동글 방지 기능입니다.)
내용   댓글달기 
이메일 문의 : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.