Microsoft MVP성태의 닷넷 이야기
Phone: 13. Android - LinearLayout 간략 설명 [링크 복사], [링크+제목 복사],
조회: 20589
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

Android - LinearLayout 간략 설명

안드로이드를 거의 사용하지 않아서 간략 기록을 남깁니다.

가령, 50:50으로 컨트롤 2개가 화면을 분할하고 싶은 경우 다음과 같은 식으로 처리할 수 있습니다.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="2"
    >
    <Button
        android:text="Test1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/test1"
        android:layout_weight="1"
    />

    <Button
        android:text="Test2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/test2"
        android:layout_weight="1"
    />
</LinearLayout>

참고로 이때 다음과 같이 layout 수치를 지정하면,

android:layout_height="100"

오류가 발생합니다.

Android - error: Error: Integer types not allowed (at 'layout_height' with value '100')

이에 대해서는 다음의 글에서 설명하듯이,

error: Error: Integer types not allowed (at 'layout_height' with value '10')
; https://stackoverflow.com/questions/27819194/error-error-integer-types-not-allowed-at-layout-height-with-value-10

단위를 적용해 주면 된다고 합니다.

android:layout_height="100dp"

근데... 단위가 너무 많군요. ^^; px, in, mm, pt, dp or dip, sp라고.




참고로, layout_weight가 꼭 비율을 의미하지는 않는 것 같습니다. 일례로 다음과 같이 하면,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="5">
    <Button
        android:text="PC On/OFF"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:id="@+id/btnTurnPCOnOff"
        android:layout_weight="4"
    />

    <Button
        android:text="Refresh"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:id="@+id/btnRefresh"
        android:layout_weight="1"
    />

</LinearLayout>

4/5와 1/5 영역으로 나누어질 것을 기대하게 되는데 약간 좀 다르게 보이는군요. ^^

turn_on_the_device_3.png

그나저나, 이것도 체계적으로 좀 보고 머릿속에서 정리를 해야 하는데 시간 상 그때그때 땜방만 하게 되니.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 6/23/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 121  122  123  124  125  126  127  128  129  [130]  131  132  133  134  135  ...
NoWriterDateCnt.TitleFile(s)
1838정성태1/4/201541464기타: 49. 윈도우 내레이터(Narrator) 기능 끄는 방법(윈도우에 파란색의 굵은 테두리 선이 나타난다면?) [4]
1837정성태1/4/201527657디버깅 기술: 68. windbg 분석 사례 - 메모리 부족 [1]
1836정성태1/4/201527606디버깅 기술: 67. windbg - 덤프 파일과 handle 정보
1835정성태1/3/201528146개발 환경 구성: 254. SQL 서버 역시 SSL 3.0/TLS 1.0만을 지원하는 듯!
1834정성태1/3/201552764개발 환경 구성: 253. TLS 1.2를 적용한 IIS 웹 사이트 구성
1833정성태1/3/201528940.NET Framework: 490. System.Data.SqlClient는 SSL 3.0/TLS 1.0만 지원하는 듯! [3]
1832정성태1/2/201521597오류 유형: 266. Azure에 응용 프로그램 게시 중 로그인 오류
1831정성태1/1/201529729디버깅 기술: 66. windbg 분석 사례 - cpu 100% 현상 (1) [1]
1830정성태1/1/201528851오류 유형: 265. svchost.exe 프로세스(IP Helper: IPHLPSVC)의 CPU 100% 현상
1829정성태12/16/201432639VC++: 86. Windows Vista부터 바뀐 Credential Provider 예제 분석 (2) [2]파일 다운로드1
1828정성태12/15/201429128VC++: 85. Windows Vista부터 바뀐 Credential Provider 예제 분석 (1) [4]파일 다운로드1
1827정성태12/12/201425505VC++: 84. CredUIPromptForWindowsCredentials Win32 API 사용법 정리
1826정성태12/11/201429842.NET Framework: 489. Socket.Listen에 전달된 backlog 인자의 의미 [6]
1825정성태12/11/201477346.NET Framework: 488. TCP 소켓 연결의 해제를 알 수 있는 방법 [10]파일 다운로드1
1824정성태12/10/201427122.NET Framework: 487. Socket.Receive 메서드의 SocketFlags.Peek 동작을 이용해 소켓 연결 유무를 확인? [8]파일 다운로드1
1823정성태12/10/201424122.NET Framework: 486. Java의 ScheduledExecutorService에 대응하는 C#의 System.Threading.Timer [2]
1822정성태12/3/201426277개발 환경 구성: 252. Xamarin 라이선스 관리 [8]
1821정성태12/1/201433107VS.NET IDE: 96. Visual Studio에서 /* ~ */ 주석을 위한 단축키(매크로)
1820정성태11/23/201421364.NET Framework: 485. Mono Profiler에서 IL 코드 변경이 가능할까? - 두 번째 이야기파일 다운로드1
1819정성태11/22/201421199오류 유형: 264. MSBuild 에러 - warning MSB3052: The parameter to the compiler is invalid,
1818정성태11/22/201424154개발 환경 구성: 251. NUMA 노드 수에 따른 IIS Worker Process(w3wp.exe) 설정 [1]
1817정성태11/22/201427250VS.NET IDE: 95. Macros for Visual Studio 2013 [1]
1816정성태11/20/201421931.NET Framework: 484. Mono Profiler에서 IL 코드 변경이 가능할까?
1815정성태11/18/201419941.NET Framework: 483. 코드로 살펴 보는 ETW의 활성화 시점 [2]
1814정성태11/18/201421443오류 유형: 263. Unable to find the requested .Net Framework Data Provider. It may not be installed.
1813정성태11/18/201423158오류 유형: 262. Build Events에 robocopy 작업이 있는 경우 "VCEnd exited with code 3" 오류 발생
... 121  122  123  124  125  126  127  128  129  [130]  131  132  133  134  135  ...