Linear layout에서 버튼을 가운데로 놓고싶은데 어떻게하면 좋을까요?
조회수 27780회
linear layout에 화면을 출력하는데요. 버튼 한개를 화면의 정중앙에 출력하고 싶어요 근데 이게 생각처럼 쉽지않아요 어떻게해도 상단에 가운데에 정렬이돼요...
밑에는 제 xml인데 어떻게 하면 좋을까요?
소스코드
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton android:id="@+id/btnFindMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/findme"></ImageButton>
</LinearLayout>
1 답변
-
화면 정중앙에 출력을하고싶으시면 LinearLayout을 쓰시면 안됩니다.
대신 RelativeLayout을 쓰세요. 그래서 android:layout_gravity="center_vertical|center_horizontal" 이부분을 RelativeLayout에서 android:layout_centerInParent="true"로 대체하세요.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageButton android:id="@+id/btnFindMe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="@drawable/findme"></ImageButton> </RelativeLayout>
이런식으로요.
댓글 입력