Android 防止图像和按钮重叠
您有两个选择: 1-使用线性布局: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
<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>