안드로이드 입문을 하다.
주변 지인의 소개로 시작을 해봤는데, 몸이 좋지 못한지라 틈틈히 공부해보고 있습니다.
예전에 학부생일때 위피로 프로그래밍을 조금 배워서 접근하는데 약간(?) 편했습니다.
누구나 초반에는 어플리케이션의 레이아웃을 짜는 방법 때문에 고민을 할것입니다.
(설마... 아니면 어떻하지? 아닐꺼야... )
안드로이드 2.1기준으로 적어봅니다.
[ Linearlayout 의 weight 속성을 이용하자]
- 요놈 생각보다 마법같은 속성입니다.
안드로이드 폰의 경우 해상도가 너무!!! 다양해서 Normal 사이즈(320x 480)크기로
레이아웃을 설계하고 나면 큰 해상도인 갤럭시 탭같은 장치로 옮기고 나면
320X480 나머지 부분은 완전히 검은색으로 나오는 우울한 결과를 볼 수 있습니다.
그래서 사용하는 방법이 가로로 늘리고 싶으면 속성을 android:layout-width="fillpraent"로
주게 됩니다. 만약, LinearLayout (가로 fillparent) 안에 ImageView가 5개있다고 하면
이때 ImageView에 weight속성을 1으로 주면됩니다.
아래는 일부 제가 만든 소소의 코드입니다.
<LinearLayout android:layout_marginTop="5dip" android:background="#ffffff" android:layout_width="fill_parent" android:layout_height="50dip" >
<ImageView android:layout_weight="1" android:layout_gravity="center_vertical" android:id="@+id/icon1" android:src="@drawable/img_100" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitCenter" />
<ImageView android:layout_weight="1" android:layout_gravity="center_vertical" android:id="@+id/icon2" android:src="@drawable/circle100" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitCenter" />
<ImageView android:layout_weight="1" android:layout_gravity="center_vertical" android:id="@+id/icon3" android:src="@drawable/a100" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitCenter" />
<ImageView android:layout_weight="1" android:layout_gravity="center_vertical" android:id="@+id/icon4" android:src="@drawable/love" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitCenter" />
<ImageView android:layout_weight="1" android:layout_gravity="center_vertical" android:id="@+id/icon5" android:src="@drawable/m100" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="fitCenter" />
</LinearLayout>
죄송합니다.(__) 아직 블로그 게시물을 보기좋게 작성할줄 몰라서.. 개선해 나가겠습니다.
위 코드를 보시면 이미지 5개를 weight = "1"속성을 통해서 Linearlayout android:layout_width="fill_parent" 차지하고 있는 가로 크기를 스스로 5등분해서 사용합니다.
편리하죠?
이것뿐만이 아닙니다.
만약 화면에서 반드시 표시해야할 레이아웃 위젯 부분이 있다면 나머지를 weight="1"로 주고
나타낼 부분을 weight="0"을 주면서 직접 DIP를 주면됩니다.
아래는 직접 짠 소스중 일부입니다.(부끄)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/android" android:id="@+id/InfoStoryPage" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="50dip" android:background="#ffffff" android:gravity="center|center_vertical">
<LinearLayout android:id="@+id/InfoStoryPage_Layout_PreviewBtn_Title" android:gravity="center" android:background="#a2a2a2" android:layout_width="wrap_content" android:layout_height="50dip" android:layout_weight="1">
<Button android:id="@+id/InfoStoryPage_PreviewBtn_Title"
android:text="이전"
android:layout_width="56dip"
android:layout_height="45dip"
android:layout_marginTop="3dip"
/>
</LinearLayout>
<LinearLayout android:gravity="center" android:background="#a2a2a2" android:id="@+id/InfoStoryPage_Layout_TextView_Title" android:layout_width="wrap_content" android:layout_height="50dip" android:layout_weight="3">
<TextView
android:id="@+id/InfoStoryPage_TextView_Title"
android:textStyle="bold"
android:layout_gravity ="center"
android:text="제품명"
android:textSize="25dip"
android:layout_width="192dip"
android:layout_height="50dip"
android:textColor="#ffffff"
android:singleLine="true"
android:gravity="center"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
/>
</LinearLayout>
<LinearLayout android:id="@+id/InfoStoryPage_Layout_Buttons_Title" android:gravity="center" android:background="#a2a2a2" android:layout_width="wrap_content" android:layout_height="50dip" android:layout_weight="1">
<Button android:id="@+id/InfoStoryPage_SearchBtn_Title" android:layout_width="56dip" android:text="찾기" android:layout_height="45dip" android:layout_marginTop="3dip" />
<Button android:id="@+id/InfoStoryPage_WriteBtn_Title" android:layout_width="56dip" android:text="쓰기" android:layout_height="45dip" android:layout_marginTop="3dip" android:visibility="gone" />
</LinearLayout>
</LinearLayout>
<LinearLayout android:gravity="center" android:background="#ff00ff" android:id="@+id/InfoStoryPage_Layout_Btns_MainFrame" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:text="기본정보" android:id="@+id/InfoStoryPage_Btn01_MenuNum1Info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:background="#000000" android:textColor="#ffffff" />
<TextView android:text="스토리" android:id="@+id/InfoStoryPage_Btn02_MenuNum1Info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:background="#ffff00" android:textColor="#000000" />
</LinearLayout>
<!-- 제품 기본정보 탭 -->
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/android" android:id="@+id/InfoStoryPage_Layout_Tap01_MenuNum1Info" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#000000" >
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#000000" >
<ImageView android:id="@+id/InfoStoryPage_Img_MenuNum1Info" android:adjustViewBounds="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/init_loading"/>
<Button android:id="@+id/InfoStoryPage_BtnWriteStory_MenuNum1Info" android:text="스토리 쓰기" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView android:id="@+id/InfoStoryPage_Scroll_DetailInfo_MenuNum1Info" android:layout_marginTop="5dip" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="@+id/InfoStoryPage_DetailInfo_MenuNum1Info" android:text="제품 설명" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/description_background" android:textColor="#000000"/>
</ScrollView>
</LinearLayout>
<!-- 스토리탭 -->
<LinearLayout xmlns:android="
http://schemas.android.com/apk/res/android" android:id="@+id/InfoStoryPage_Layout_Tap02_MenuNum1Info" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffff00" android:visibility="gone">
<ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff00ff"/>
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="64dip" android:background="#00ff00" android:layout_weight="0">
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="64dip" android:background="#00ff00" android:layout_weight="1">
<ImageView android:id="@+id/btn_Menu_Num1" android:src="@drawable/menu_button1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:scaleType="fitXY" />
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="64dip" android:background="#00ff00" android:layout_weight="1">
<ImageView android:id="@+id/btn_Menu_Num2" android:src="@drawable/menu_button2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff00ff" android:scaleType="fitXY" />
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="64dip" android:background="#00ff00" android:layout_weight="1">
<ImageView android:id="@+id/btn_Menu_Num3" android:src="@drawable/menu_button3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:scaleType="fitXY" />
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="64dip" android:background="#00ff00" android:layout_weight="1">
<ImageView android:id="@+id/btn_Menu_Num4" android:src="@drawable/menu_button4" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff00ff" android:scaleType="fitXY" />
</LinearLayout>
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="64dip" android:background="#00ff00" android:layout_weight="1">
<ImageView android:id="@+id/btn_Menu_Num5" android:src="@drawable/menu_button5" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:scaleType="fitXY" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
[아래와 같은 결과화면이 뜨게 됩니다. - 세부적인 코딩은 따로 해줘야 합니다.]