2016-11-05 1 views

답변

0

아이디어는 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> 

출력 :이 내 솔루션입니다

1

는 RelativeLayout의를 사용하고 이미지 뷰에 대한 XML에

android:centerInParent="true"

을 설정합니다. ImageButton을 중앙으로 설정하고 RightOf 속성을 ImageButton에 추가합니다.

0

. 올바른 위치 지정을 위해서는 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>