마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

alignParentBottom 사용시 공백이 사라집니다.

0 추천

 

안녕하세요. 

위쪽에 공백을 주고 아래에 저장 버튼을 만드려고 weight를 이용해 공백을 주었는데요

저장버튼을 만들고 아래로 설정하려니 위에 공백이 없어지네요;;

저장 버튼을 다른 레이아웃을 만들어 넣어봐도 계속 위에 공백이 없어지는데 

좋은 방법이 없을까요;;

<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:weightSum="1" 
    tools:context="com.example.misson5.MainActivity">
    
    <LinearLayout  
   		 android:layout_width="match_parent" 
   		 android:layout_height="wrap_content"
   		 android:layout_weight="0.2">
    </LinearLayout>
   
   <RelativeLayout 
    	android:layout_width="wrap_content"
    	android:layout_height="wrap_content"> 
    <!--  이름 뷰   -->
    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="25sp"
        android:padding="10dp"
        android:text="@string/name" />
    
    <EditText 
        android:id="@+id/nameInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/name"
        android:padding="5dp"
        android:layout_margin="10dp"
        android:background="@drawable/border" 
        android:inputType="text"/>
   	
   	<!--  나이 뷰 -->
   	<TextView
        android:id="@+id/age"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:layout_below="@id/name"
        android:layout_alignLeft="@id/name"
        android:textSize="25sp"
        android:padding="10dp"
        android:text="@string/age" />
    
    <EditText 
        android:id="@+id/ageInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/nameInput"
        android:layout_toRightOf="@id/age"
        android:padding="5dp"
        android:layout_margin="10dp"
        android:background="@drawable/border" 
        android:inputType="number"/>
    
    <!--  생년월일  뷰 -->
    
    <TextView
       android:id="@+id/BirthDate"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textStyle="bold"
       android:layout_below="@id/age"
       android:layout_alignLeft="@id/age"
       android:textSize="25sp"
       android:padding="10dp"
       android:text="@string/birthdate" />
    
    <Button
       android:id="@+id/BirthDateBtn"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_below="@id/BirthDate"
       android:padding="10dp"
       android:layout_marginLeft="30dp"
       android:layout_marginRight="30dp"
       android:text="" />
    <!--  저장 버튼 -->
    
    <Button
       android:id="@+id/save"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
	   android:layout_centerHorizontal="true"
	   android:layout_alignParentBottom="true"
       android:text="저  장" />
    
    </RelativeLayout>
</LinearLayout>

 

douglas (340 포인트) 님이 2015년 1월 31일 질문

3개의 답변

+1 추천
 
채택된 답변
<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="0.8">
alkyne (22,960 포인트) 님이 2015년 1월 31일 답변
douglas님이 2015년 2월 3일 채택됨
정확히 알려주셨네요!! 정말 감사합니다!!
0 추천
레이아웃이 이해하기가 힘드네요
리니어레이아웃하나는 왜있는지 모르겠고..
여백을 원하시면 위아래 패딩을 주시면 될텐테요
mamondebaltob (32,750 포인트) 님이 2015년 1월 31일 답변
아 리니어 레이아웃은 weight를 이용해 20%만 세로로 공백을 주기위해 넣었습니다.
여백만을 위하신거라면 relativelayout 를 루트로 빼고
자바단에서 스크린 높이 20퍼센트를 paddingTop 주시는 방법이 있구요

보통은 걍 dp 로 줍니다

정 weight 를 쓰시고 싶으시면 api14 에서 소개된 space 를 쓰시면 되세요
0 추천

<RelativeLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent">
 
    <Button
       android:id="@+id/save"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
       android:layout_alignParentBottom="true"
       android:layout_margin="10dp"
       android:text="저  장" />

nicehee (73,100 포인트) 님이 2015년 1월 31일 답변
nicehee님이 2015년 1월 31일 수정
으.. 그래도 위에 공백은 사라지네요 ㅠㅠ
그럼 버튼에 패딩대신 마진을 줘보셔요
android:layout_margin="10dp"
...