我是android的新手,我创建了一个基本的activity,但在我的手机上,它被颠倒了(左显示在右,右显示在左)以获得一些响应。
所以如果android studio上的窗口是这样的:
┌────────────┐ │button │ │ │ │ │ └────────────┘
所以在我的手机上是这样的:
┌────────────┐ │ button│ │ │ │ │ └────────────┘
我试图在activity的末尾添加finish();
,但应用程序无法启动。 我该怎么修好呢?
Android工作室
我的电话
欢迎来到Stack。 这段代码对我来说在所有设备和所有版本上都很好。
1-AndroidManifest.xml:
<application
...
android:supportsRtl="true" >
...
</application>
2-父级中的任何布局:
android:layoutDirection="ltr"
示例:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr" >
<Button
android:text="login"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>
当出现这种错误时,我总是将布局的根父级更改为约束布局。 如果您这样做,并且相应地设置约束,则不可能发生这种情况。
当我开始使用它时,这个视频帮助了我:https://www.youtube.com/watch?v=mtybbinie8
在这里您可以找到非常好的官方文档:https://developer.android.com/training/constraint-layout
如果您不想使用约束布局,请分享您的XML代码,我们将尝试以另一种方式帮助您。