모바일/안드로이드앱
Android Studio / 안드로이드 앱만들기 공부7 / layout_width, layout_margin, padding / 뷰의 마진 패딩 width를 이용한 뷰 나누기
yy_dd2
2020. 9. 10. 00:22
반응형
조금 쉬고 논다고 계속 책을 안봐서 정리하기...
margin padding은 html css 같은 기본적인것을 한 사람이라면 다들 알것
설명은 생략 하지만 초보자 분들이 검색 할 수 있으니 잠깐 쓴다면
margin은 생성된 A박스와 B박스의 거리라고 이해하면 쉽고
padding은 A박스 안에 쓰여진 글씨의 크기를 박스안에서 어느정도의 공간을 둘건지 보는것
딱히 확인할건 코드뿐이였어서 코드로만 메모해두기
app/res/layout 폴더에 새파일을 만들어서 했음
match_parent 읽히는 그대로 부모창에 매치한다는 것
최상위 LinearLayout을 부모창에 매치하고 LinearLayout 안에 LinearLayout을 만들어서 코드 작성함
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#ffff0000"
android:textSize="24sp"
android:background="#ffffff00"
android:padding="10dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#ffff0000"
android:textSize="24sp"
android:background="#ff00ffff"
android:layout_margin="10dp"/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#ffffff"
android:textSize="24sp"
android:background="#fff00fff"
android:padding="20dp" />
</LinearLayout>
android:layout_margin="" 이랑 android:padding=""만 확인하면된다
안드로이드스튜디오에서 사용하는 dp는 어떤기준의 사이즈인지 아직 모르겠다.
다음에 찾아보는 것으로.
android:layout_weight는 여유공간을 분할하는 속성임
화면의 비율로 따져서 1:1 1:2 이런식으로 비율을 나눠줌
<?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">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff00"
android:text="텍스트"
android:textColor="#ffff0000"
android:textSize="24dp"
android:layout_weight="1"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff00ffff"
android:text="텍스트"
android:textColor="#ffff0000"
android:textSize="24dp"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff00"
android:text="텍스트"
android:textColor="#ffff0000"
android:textSize="24dp"
android:layout_weight="1"
/>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff00ffff"
android:text="텍스트"
android:textColor="#ffff0000"
android:textSize="24dp"
android:layout_weight="2"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#ffffff00"
android:text="텍스트"
android:textColor="#ffff0000"
android:textSize="24dp"
android:layout_weight="1"
/>
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff00ffff"
android:text="텍스트"
android:textColor="#ffff0000"
android:textSize="24dp"
android:layout_weight="2"
/>
</LinearLayout>
</LinearLayout>
쓰고나면
이렇게 나옴
** LinearLayout 안에 LinearLayout이 들어갈수있고 여러개 생성 될 수 있다
반응형