2013-07-23 3 views
-1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    <ImageView 
     android:id="@+id/showImg" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:contentDescription="@string/showImg" 
    /> 

    <Button 
     android:id="@+id/photo" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignTop="@+id/showImg" 
     android:text="@string/photo" 
    /> 
</RelativeLayout> 

위의 코드 이미지보기를 실행하면 사진 단추가 표시됩니다.이미지 및 단추 겹침 방지

어떻게해야합니까?

1 사용의 LinearLayout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical"> 
    <ImageView 
     android:id="@+id/showImg" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:contentDescription="@string/showImg" 
     /> 

    <Button 
     android:id="@+id/photo" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/photo" /> 
</LinearLayout> 

2를 사용하여 속성 layout_below :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"> 
    <ImageView 
     android:id="@+id/showImg" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:contentDescription="@string/showImg" 
    /> 

    <Button 
     android:id="@+id/photo" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/showImg" 
     android:text="@string/photo" 
    /> 
</RelativeLayout> 

난 당신이 버튼 위의 이미지를 원하는 있으리라 믿고있어

+0

어떻게하면 좋을까요? – KOTIOS

+1

버튼에는 drawableLeft, drawableRight, drawableTop 및 drawableBottom 속성이 있습니다. 시도해보십시오, 당신은 imageView가 전혀 필요하지 않습니다. –

답변

1

당신은 두 가지 옵션이 있습니다. 그렇지 않으면 layout_above, layout_toLeftOf 또는 layout_toRightOf를 사용할 수 있습니다.

+0

예 – Dilshi