简体   繁体   English

android:从纵向模式转到横向模式时按钮未居中

[英]android: button not centered when turned from portrait to landscape mode

I have an ImageButton in relative layout with following setup: 我有以下设置相对布局中的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>

It's in both layout and layout-land file. 它在layout和layout-land文件中。

The button is centered in landscape mode correctly when app started as landscape mode, kept centered when turn the device to portrait mode. 当应用程序以横向模式启动时,按钮在横向模式下正确居中;在将设备转到纵向模式时,该按钮保持居中。

The button is centered in portrait mode correctly when app started as portrait mode, but not centered anymore when turn the device to landscape mode. 当应用程序以纵向模式启动时,按钮在纵向模式下正确居中,但在将设备切换为横向模式时,按钮不再居中。 Not sure why? 不知道为什么吗?

add

android:configChanges="orientation"

in activity used in your androidmanifest.xml file androidmanifest.xml文件中使用的活动
It should work 它应该工作
https://developer.android.com/guide/topics/manifest/activity-element.html#config https://developer.android.com/guide/topics/manifest/activity-element.html#config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM