CSS - Image 겹치기
이미지를 겹치기 위해서 Style 프로퍼티의 Position을 이해해야 한다.
position의 default 값은 static이며 이는 해당 document에 그려지는 element 순서대로 위치하게 한다.
relative는 기본 위치에서 해당 element를 이동시켜준고 td 정렬 기준으로 div 전반부를 사용한다.
absolute는 가장 가까운 곳에 위치한 조상 엘리먼트에 상대적으로 위치가 조정된다.
코드의 구조가 td > div > img 로 되있었으므로 다음과 같이 작성하면 해당 td에 들어가는 이미지에 한해서 겹쳐지게 된다.
<td>
<div style="position: relative;">
<img style="position: absolute;"/>
</div>
</td>
absolute 로 지정하면 td 정렬 기준으로 div 왼쪽 영역부터 채워지니 이점 고려해서 left, top, padding 프로퍼티 값을 부여해서 컨트롤 하면 원하는 위치로 img 태그를 놓을 수 있다.
'개발 > [언어] CSS' 카테고리의 다른 글
[생활코딩][CSS] 캐스케이딩 cascading (0) | 2016.12.06 |
---|---|
[생활코딩][CSS] 다양한 선택자들 CSS 선택자 (0) | 2016.12.05 |
[생활코딩][CSS] px vs em vs rem (0) | 2016.12.05 |
[css] 이미지에 색 필터 넣기 (0) | 2016.11.13 |
[css] input text속성 (0) | 2016.11.10 |
[안드로이드] Android Service 개념 및 사용방법 [펌]
<안드로이드 Application을 구성하는 4가지 컴포넌트>
자 그러면, Service에 대해 알아보겠습니다. 아래의 그림에서 빨간색 중요 표시가 되어 있는 컴포넌트에 대한 설명입니다.
1. Service란 무엇인가? |
Service는 안드로이드 Application을 구성하는 4가지 컴포넌트 중에 하나이며, Activity처럼 사용자와 상호작용 하는 컴포넌트가 아니고, Background(화면뒷단)에서 동작하는 컴포넌트를 말합니다.
2. Service는 왜 필요한가? |
3. Service 사용방법 |
Service의 종류에는 2가지가 있습니다. 1번째는 startService()를 이용한 방법이고, 2번째 방법은 bindService()를 이용하는 방법 입니다. 2가지의 차이점에 대해서는 나중에 얘기를 해보도록 하구요. 이번 포스팅 에서는 1번째 방법만 설명 하도록 하겠습니다.
Service 실행 : startService(Intent Serivce) 메서드 호출.
Service 중지 : stopService(Intent Serivce) 메서드 호출.
4. Service 사용시 주의사항 |
4.1. Service의 ANR 발생 |
Android는 Linux 기반의 프로그램 입니다. 프레임웍 단에는 Linux로 구현되어 있습니다. 메모리 관리 또한 Linux Kernel에서 해주게 되는데요.
하나의 프로세스를 자세히 살펴보면, 아래와 같은 구조를 가지고 있습니다.
여기서 주의 해야 할 점은, 모든 컴포넌트들이 Main Thread 안에 실행된다는 점 입니다. Main Thread는 앞서 Thread의 예제에서 살펴봤듯이, UI 작업을 처리해주는 Thread 입니다. Service 역시 Main Thread에서 관리하는 녀석이므로, Thread 작업이 필요한 경우, 작업Thread를 생성해서 관리해줘야 한다는 점 입니다.
아니면 ANR이 발생하여, 종료시켜 버리게 됩니다. 그렇기 때문에 Service사용시에도 Thread작업이 필요할 경우에는, 별도의 작업Thread를 만들어서 사용해야 합니다. 이점 유의해 주시기 바랍니다.
4.2. Service의 실행 중에 startService() 호출 |
Service 실행중에 startService() 메서드를 호출하게 되면 어떤 현상이 발생 할까요? 일반적으로 Service가 무한정 생성될거 같은데요, Service 실행도중에 startService() 메서드를 실행하게 되면 Service의 onStartCommand() 메서드를 호출 하게 합니다.
Service 주기는 onCreate() -> onStartCommand() 순으로 이뤄 지는데요, Service가 실행되고 있는 도중에 다시한번 startService() 메서드가 호출되면 onStartCommand() 주기 부터 실행하게 됩니다. 마치 Activity의 onResume() 처럼 말이죠. 그렇기 때문에 중요한 작업에 대해서는 onCreate() 보다는 onStartCommand() 메서드에 구현을 해줘야 합니다.
안드로이드 2.0 이하 버전의 Service의 주기는 onCreate() -> onStart() 구조 였지만, 2.0 이상 부터는 Service의 문제점과 기능을 보완하여 onStart()메서드 대신 onStartCommand() 메서드 사용을 권장하고 있습니다. 현재 onStart() 메서드를 사용해도 상관은 없지만 구글에서 권장하는 onStartCommand() 메서드를 사용하는게 실제 사용시 좀 더 다양한 기능을 사용 할 수 있습니다.
[기존 Service Life cycle]
[2.0 이후의 Service Life cycle]
5. Service onStartCommand() 사용방법 |
Service는 기본적으로 프로세스에 의해 종료가 되더라도 다시 살아나는 구조를 가지고 있습니다. Service의 종료메서드인 stopService() 메서드를 호출 하기 전까지는 말이죠.
프로세스에 의해 종료된 Service는 onCreate() -> onStartCommand() 순으로 주기를 타게 됩니다. startService() 메서드를 호출하지 않았기 때문에 정상적으로 동작 하는 것이지요.
onStartCommand() 메서드는 3가지 리턴 타입을 갖게 되는데요.
|
일단 기본적인 리턴방법에 대해 알아봤습니다. 그런데 보통 Service Class를 상속받고 onStartCommand() 메서드를 오버라이드 하면 아래와 같은 형태의 메서드가 기본 형태인데요. 위에서 알아본 3가지 리턴방식과는 다른 모양 입니다.
음 이건 몰까요? 이것 역시 START_STICKY 과 동일한 리턴 타입 입니다. START_STICKY 플래그(FLAG)의 값은 상수 1이고 super.onStartCommand(intent, flags, startId) 역시 상수 1을 리턴 합니다. 그렇기 때문에 START_STICKY 와 동일게 동작 합니다.
6. Service의 종류 |
Service의 종류가 2가지가 있다고 위에서 잠깐 언급했었는데요. 2가지 방식의 Service를 살펴 보자면 첫번째로 지금 까지 설명했던 1번 startService() 메서드에 의한 실행방법이 있습니다. 이 Service는 현재 실행중인 프로세스안에서의 동작을 하게 되는 Service 입니다.
이 처럼 하나의 프로세스 안에서 해당 패키지 내의 다른 컴포넌트들과의 유기적으로 통신하는 어플리케이션의 역할을 하고 있습니다.
2번째 bindService()로 실행하는 방법은
프로세스 내에서 다른컴포넌트들과 서로 유기적으로 통신을 하며, 다른 프로세스(어플리케이션)와도 Data 공유 및 통신을 하게 되는 Service를 실행하는 방법입니다.
bindService()에 관한 내용은 다음 포스팅때 설명하도록 하겠습니다.
'개발 > [앱] Android' 카테고리의 다른 글
[android] java파일에서 actionbar hide (0) | 2016.11.07 |
---|---|
[Android] Button을 처리하는3가지 방법 (0) | 2016.05.11 |
[자료구조] Select Sort
Select sort는 정렬이 되지 않은 전체 배열에서 하나를 선택하여 위치를 교환하는 정렬방법이다.
1) 7[0] 을 선택한 뒤 배열 [1]~[6] 까지 중 가장 작은 수를 선택한다. 가장 작은 수 = 1[6]
2) 가장 작은 수 1[6]과 7[0]의 자리를 swap 한다.
3) 그다음 4[1]를 선택한 뒤 배열 [2]~[6] 가장 작은 수를 선택한다. 가장 작은 수 = 2[5]
4) 끝에 도달할 때 까지 반복한다.
ex)
void sort(int *a, const int n)
{ // Sort the n integers a[0] to a[n-1] into nondecreasing order.
for (int i = 0; i < n; i++)
{
int j = i;
// find smallest integer in a[i] to a[n-1]
for (int k = i + 1; k < n; k++)
if (a[k] < a[j]) j = k;
swap(a[i], a[j]);
}
}
'개발 > 자료구조' 카테고리의 다른 글
[자료구조] c++ 스택 (0) | 2016.11.17 |
---|---|
[자료구조] [C++] CircularQueue 사이클 큐 (0) | 2016.11.16 |
q_sort (1) | 2016.11.16 |
Recursive 를 이용한 Permutation Generator (순열 생성기) (0) | 2016.10.25 |
Binary Search 이진 탐색 (0) | 2016.10.25 |
Recursive 를 이용한 Permutation Generator (순열 생성기)
perm(a, b, c, d);
1) a + perm(b, c, d)
2) b + perm(a, c, d)
3) c + perm(a, b, d)
4) d + perm(a, b, c)
perm(b, c, d)
1) b + perm(c, d)
2) c + perm(b, d)
3) d + perm(b, c)
perm(c, d)
1) c + perm(d)
2) d + perm(c)
perm(a, 0, n) → a[0], a[1], ⋯, a[n-1]
소스 C++)
void Permutations (char *a, const int k, const int m)
{// Generate all the permutations of a[k], ..., a[m].
if (k == m) { // output permutation
for (int i = 0; i <= m; i++) cout << a[i] << “ “;
cout << endl;
}
else // a[k:m] has more than one permutation. Generate these recursively
for (int i = k; i <= m; i++) {
swap(a[k], a[i]);
Permutations(a, k+1, m);
swap(a[k], a[i]);
}
}
'개발 > 자료구조' 카테고리의 다른 글
[자료구조] c++ 스택 (0) | 2016.11.17 |
---|---|
[자료구조] [C++] CircularQueue 사이클 큐 (0) | 2016.11.16 |
q_sort (1) | 2016.11.16 |
[자료구조] Select Sort (0) | 2016.10.26 |
Binary Search 이진 탐색 (0) | 2016.10.25 |
Binary Search 이진 탐색
Binary Search란
< 그림으로 설명 >
[이진 탐색]
left, right: 배열(a[0], a[1], ⋯, a[n-1])의 왼쪽, 오른쪽 끝 지점
초기 값으로 left = 0, right = n-1
list의 중간 위치 middle = (left + right) / 2로 설정
a[middle]과 x를 비교할 경우 3가지 경우 중에 하나를 고려
⑴ x > a[middle]: left를 middle+1로 설정
⑵ x < a[middle]: right를 middle-1로 설정
⑶ x = a[middle]: middle을 반환
예시) C++
int BinarySearch (int *a, const int x, const int n){ // x - 찾으려는 값, n = 배열의 원소 수 or 찾으려는 배열의 크기
int left = 0, right = n -1;
// 찾거나 left가 right 넘어갈 경우 멈춘다.
while(left <= right){
int middle = (left + right) / 2; //중간위치 항상
if(x > a[middle]) left = middle + 1 ;
else if (x < a[middle]) right = middle - 1;
else return middle //찾앗다.
}
//못 찾았다.
return -1;
}
'개발 > 자료구조' 카테고리의 다른 글
[자료구조] c++ 스택 (0) | 2016.11.17 |
---|---|
[자료구조] [C++] CircularQueue 사이클 큐 (0) | 2016.11.16 |
q_sort (1) | 2016.11.16 |
[자료구조] Select Sort (0) | 2016.10.26 |
Recursive 를 이용한 Permutation Generator (순열 생성기) (0) | 2016.10.25 |
[알고리즘] Graph - DFS(깊이 우선 탐색) [ 펌 - manducku]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
package Graph_07;
import java.util.*;
public class DfsTest { static int nE; static int nV; static int[][] ad; static boolean[] visit; public static void dfs(int i){ visit[i] = true; // 함수 호출 시, visit 했음을 표시
System.out.print(i+ " "); for(int j = 1; j < nV+1; j++){ if(ad[i][j] == 1 && visit[j] == false){ // j를 방문하지 않았으면 j를 방문한다.
dfs(j); } } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); nV = scan.nextInt(); nE = scan.nextInt(); ad = new int[nV+1][nV+1]; // 변수 초기화
visit = new boolean[nV+1]; // 변수 초기화
for(int i = 0; i < nE; i++){ int t1 = scan.nextInt(); int t2 = scan.nextInt(); ad[t1][t2] = ad[t2][t1] = 1; } dfs(1); // 1번부터 탐색 시작
} } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
package Graph_07;
import java.util.*;
public class DfsTest02 { static int Nv; static int Ne; static boolean[] visit; static ArrayList<ArrayList<Integer>> ad; public static void dfs(int i){ visit[i] = true; System.out.print(i); for(int j : ad.get(i)){ // 배열 null check
if(visit[j] == false){ dfs(j); } } } public static void main(String[] args){ Scanner scan = new Scanner(System.in); Nv = scan.nextInt(); Ne = scan.nextInt(); ad = new ArrayList(Nv+1); // 인접 리스트 초기화
visit = new boolean[Nv+1]; // visit 배열 초기화
for(int i = 0; i < Nv+1; i++){ // 인접 리스트 속의 리스트 초기화
ad.add(new ArrayList()); } for(int i = 0; i < Ne; i++){ int t1 = scan.nextInt(); int t2 = scan.nextInt(); ad.get(t1).add(t2); ad.get(t2).add(t1); } dfs(1); } } | cs |
'개발 > 알고리즘' 카테고리의 다른 글
[알고리즘] Graph - BFS (너비 우선 탐색) [펌 - manducku] (0) | 2016.10.22 |
---|
[알고리즘] Graph - BFS (너비 우선 탐색) [펌 - manducku]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
package Graph_07;
import java.util.*;
public class BfsTest01 { static int Ne; static int Nv; static int[][] ad; static boolean[] visit; public static void bfs(int i){ Queue<Integer> q = new <Integer> LinkedList(); HashMap <Integer, Boolean> hash = new HashMap<Integer, Boolean>(); //hash Map을 이용하여 queue 입력여부 확인
q.offer(i); while(!q.isEmpty()){ int temp = q.poll(); visit[temp] = true; System.out.print(temp); for(int j =1; j <= Ne; j++){ if(ad[temp][j] == 1 && visit[j] == false){ if(!hash.containsKey(j)){ q.offer(j); hash.put(j, true); } } } } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); Ne = scan.nextInt(); Nv = scan.nextInt(); ad = new int[Nv+1][Nv+1]; visit = new boolean[Nv+1]; for(int i = 0; i < Nv; i++){ int t1, t2; t1 = scan.nextInt(); t2 = scan.nextInt(); ad[t1][t2] = ad[t2][t1] = 1; } bfs(1); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
package Graph_07;
import java.util.*;
public class BfsTest02 { static int[][] ad; static boolean[] visit; static int Ne, Nv; public static void bfs(int i){ Queue <Integer> q = new <Integer> LinkedList(); q.offer(i); visit[i] = true; while(!q.isEmpty()){ int temp = q.poll(); System.out.print(temp); for(int j = 1; j <= Nv; j++){ if(ad[temp][j] == 1 && visit[j] == false){ q.offer(j); visit[j] = true; // 큐에 넣을 노드들을 잠재적으로 방문한다는 가정하에 입력
} } } } public static void main(String[] args){ Scanner scan = new Scanner(System.in); Nv = scan.nextInt(); Ne = scan.nextInt(); ad = new int[Nv+1][Nv+1]; visit = new boolean[Nv+1]; for(int i = 0; i < Ne; i++){ int t1, t2; t1 = scan.nextInt(); t2 = scan.nextInt(); ad[t1][t2] = ad[t2][t1] = 1; } bfs(1); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
package Graph_07;
import java.util.*;
public class Bfs03 { static ArrayList<ArrayList<Integer>> ad; static boolean[] visit; static int Ne, Nv; public static void bfs(int i){ Queue <Integer>q = new <Integer> LinkedList(); HashMap<Integer, Boolean> hash = new HashMap<Integer, Boolean>(); q.offer(i); while(!q.isEmpty()){ int temp = q.poll(); visit[temp] = true; System.out.print(temp); for(int j : ad.get(temp)){ if(visit[j] == false && !hash.containsKey(j)){ q.offer(j); hash.put(j, true); } } } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); Nv = scan.nextInt(); Ne = scan.nextInt(); ad = new <ArrayList<Integer>> ArrayList(Nv+1); visit = new boolean[Nv+1]; for(int i = 0; i <= Nv+1; i++){ ad.add(new ArrayList()); } for(int i = 0; i < Ne; i++){ int t1, t2; t1 = scan.nextInt(); t2 = scan.nextInt(); ad.get(t1).add(t2); ad.get(t2).add(t1); } bfs(1); } } | cs |
'개발 > 알고리즘' 카테고리의 다른 글
[알고리즘] Graph - DFS(깊이 우선 탐색) [ 펌 - manducku] (0) | 2016.10.22 |
---|
[Java] StringBuffer 일정 범위 문자열 삭제 [펌]
StringBuffer에 delete 메소드를 사용하면 특정 범위의 문자열을 삭제할 수 있습니다.
delete(시작index, 끝index) 로 사용하면 됩니다.
index는 문자 순서가 아니라 문자와 문자 사이의 index입니다.
0a1b2c3 이런식으로 계산해야 합니다.
아래는 index 2~6까지 삭제를 해서 출력한 샘플 입니다.
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("abcdefghijkl");
System.out.println(sb);
sb.delete(2, 6);
System.out.println(sb);
}
출력 결과는 아래와 같습니다.
abcdefghijkl
abghijkl
부트스트랩 navbar 가운데 로고 넣기
<div class="container">
<!-- 상단 네비게이트 바 -->
<div class="navbar nav-tabs navbar-fixed-top" style="background-color:white; border-bottom:1px solid gray">
<div class="container">
<!-- 왼쪽 메뉴 버튼 -->
<div class="col-xs-3" style="background-color:white">
<button type="button" class="btn btn-default" style="margin-top:4px">
<span class="glyphicon glyphicon-align-justify" style="font-size:25px"></span>
</button>
</div>
<!-- 가문데 로고 -->
<div class="col-xs-6" style="background-color:white-space; text-align:center; display:inline-block;">
<button type="button" class="btn btn-default btn-lg" style="margin-top:2px">
트래블쉽
</button>
</div>
<!-- 오른쪽 로그인, 회원가입-->
<div class="col-xs-3" style="background-color:white">
<button type="button" class="btn btn-default" style="margin-top:10px; float:right;">
<span class="glyphicon glyphicon-user"> 로그인 </span>
</button>
</div>
</div>
</div>
</div>
'개발 > [웹프론트] 부트스트랩(bootstrap)' 카테고리의 다른 글
[부트스트랩] datetimepicker, selectpicker 사이트 (0) | 2016.11.10 |
---|---|
carousel의 carousel-inner 검정 배경 전체로 채우기 (0) | 2016.10.21 |
부트스트랩 가운데 정렬 (0) | 2016.10.13 |
부트 스트랩 공부하면서 정리한 것 (w3school) (1) | 2016.10.03 |
carousel의 carousel-inner 검정 배경 전체로 채우기
carousel
*는 직접 입력하시면 됩니다.
<div class="item active">
<img src="1.jpg" alt="*" width="*" height="*" style="background-color:rgba( 0, 0, 0, 0.5 );">
<div class="carousel-caption" style="background-color:rgba( 0, 0, 0, 0.5 ); position:absolute; left:0; top:0%;width:100%; height:100%;">
<div class="text-center">
<h1 style="text-align:center"> 타이틀 </h1>
<p>내용</p>
</div>
</div>
</div>
...
...
'개발 > [웹프론트] 부트스트랩(bootstrap)' 카테고리의 다른 글
[부트스트랩] datetimepicker, selectpicker 사이트 (0) | 2016.11.10 |
---|---|
부트스트랩 navbar 가운데 로고 넣기 (0) | 2016.10.21 |
부트스트랩 가운데 정렬 (0) | 2016.10.13 |
부트 스트랩 공부하면서 정리한 것 (w3school) (1) | 2016.10.03 |