Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 防止图像和按钮重叠_Android_Layout_Android Button - Fatal编程技术网

Android 防止图像和按钮重叠

Android 防止图像和按钮重叠,android,layout,android-button,Android,Layout,Android Button,您有两个选择: 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" andro

您有两个选择:

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>

2-使用以下属性布局_:

<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>


我假设你们想要按钮上方的图像。否则,您可以使用上面的layout\u、layout\u toLeftOf或layout\u toRightOf。

您希望在哪个方向进行操作?按钮具有drawableLeft、drawableRight、drawableTop和drawableBottom属性。试试这些,你根本不需要imageView
<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>