android+studio设置图片居中
时间: 2023-12-06 09:37:42 浏览: 161
针对Android Studio设置图片居中的问题,可以通过以下两种方式实现:
1.使用RelativeLayout布局,将ImageView的layout_centerInParent属性设置为true,即可实现图片居中显示。示例代码如下:
```xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image"
android:layout_centerInParent="true"/>
</RelativeLayout>
```
2.使用FrameLayout布局,将ImageView的layout_gravity属性设置为center,即可实现图片居中显示。示例代码如下:
```xml
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image"
android:layout_gravity="center"/>
</FrameLayout>
```
阅读全文
相关推荐















