2016-11-05 4 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を使用し、ImageViewのための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> 
関連する問題