RelativeLayout에서 버튼을 중앙에 출력하려면 어떻게 해야하죠?

조회수 3239회

relative layout에서 버튼을 중앙에 출력하고 싶은데요 어떻게 해야하나요.. gravity랑 orientation을 아무리 건드려도 소용이 없습니다..

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="#ff0000">
    
        <Button
            android:id="@+id/btn_mybutton"
            android:layout_height="wrap_content"
            android:layout_width="124dip"
            android:layout_marginTop="5dip"
            android:layout_centerHorizontal="true"/>
    
    </RelativeLayout>
    

    이렇게 해보세요. 화면의 정중앙에 오게하고싶으시다면 android:layout_centerVertical="true"도 주시면 될겁니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)