我有一个相对布局的ImageButton,具有以下设置:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000032">
<ImageButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@null"
android:contentDescription="button"
android:scaleType="fitCenter"
android:src="@drawable/buttonImage" />
</RelativeLayout>
它位于layout-layout-land文件中。
当应用程序以横向模式启动时,按钮以横向模式居中,在将设备转为纵向模式时保持居中。
当应用程序以纵向模式启动时,按钮以纵向模式正确居中,但在将设备转为横向模式时,该按钮不再居中。不确定为什么?
答案 0 :(得分:0)
添加
android:configChanges="orientation"
在androidmanifest.xml
文件中使用的活动中
它应该工作
https://developer.android.com/guide/topics/manifest/activity-element.html#config