在代码的设计部分中,我的微调器位于应用程序的中心,但是当我运行应用程序时,它一直显示在顶部。我查找了解决此问题的方法,但没有任何效果。有人可以建议什么吗?
这是我的 XML:https://gist.github.com/liliycode/43e45cd39c765716aebbdea4a4c08b89
如果需要的话,这是我的java:
https://gist.github.com/liliycode/50246841d81a65ec177283ec0a488b52
最佳答案
您应该查看此类问题的文档。
按照文档 here 中的建议,我通常使用相对布局
。
centerInParent
、centerHorizontal
和 centerVertical
非常适合这些情况。
示例,使用它们:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="American Writers"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:layout_centerHorizontal="true"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/author_names"
android:layout_centerInParent="true">
</Spinner>
</RelativeLayout>
希望对您有所帮助。
关于java - Spinner 不会出现在中心 (Android Studio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42913890/