ImageView를 화면 중앙에 배치하고 ImageButton을 ImageView 오른쪽에 배치하려면 Screen을 참조하십시오.요소를 가로 레이아웃으로 배치 (안드로이드)
어떻게하면됩니까? 나는 수평 선형 레이아웃과 중력을 시도 : 센터하지만 두 요소가 중앙에 있습니다. 사전에
감사합니다 :)
ImageView를 화면 중앙에 배치하고 ImageButton을 ImageView 오른쪽에 배치하려면 Screen을 참조하십시오.요소를 가로 레이아웃으로 배치 (안드로이드)
어떻게하면됩니까? 나는 수평 선형 레이아웃과 중력을 시도 : 센터하지만 두 요소가 중앙에 있습니다. 사전에
감사합니다 :)
아이디어는 RelativeLayout을 사용하는 것입니다. 부모님의 중심에 ImageView를 설정하십시오. 그런 다음 오른쪽에 imageButton을 놓습니다. 내 예를 참조하십시오
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff00ff00"
android:text="text1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffff0000">
<ImageView
android:id="@+id/main_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_done_white_24px"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/main_image"
android:src="@drawable/ic_account_box_black_24dp"
/>
</RelativeLayout>
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff00ff00"
android:gravity="center_vertical"
android:text="text2"/>
</LinearLayout>
출력 :이 내 솔루션입니다
는 RelativeLayout의를 사용하고 이미지 뷰에 대한 XML에
android:centerInParent="true"
을 설정합니다. ImageButton을 중앙으로 설정하고 RightOf
속성을 ImageButton에 추가합니다.
. 올바른 위치 지정을 위해서는 layout weight으로 실행하십시오.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="text"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"/>
</FrameLayout>
<TextView
android:text="text"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>