java - Spinner 不会出现在中心 (Android Studio)

标签 java android

在代码的设计部分中,我的微调器位于应用程序的中心,但是当我运行应用程序时,它一直显示在顶部。我查找了解决此问题的方法,但没有任何效果。有人可以建议什么吗?

这是我的 XML:https://gist.github.com/liliycode/43e45cd39c765716aebbdea4a4c08b89

如果需要的话,这是我的java:

https://gist.github.com/liliycode/50246841d81a65ec177283ec0a488b52

最佳答案

您应该查看此类问题的文档。

按照文档 here 中的建议,我通常使用相对布局

centerInParentcenterHorizo​​ntalcenterVertical 非常适合这些情况。

示例,使用它们:

<?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/

相关文章:

android - 链接Android NDK下的共享库

Java - 空整数数组

java - CardView 中的进度条在 Recyclerview 中不起作用

java - @RelatedTo(elementClass = Concept.class)RelatedTo.elementClass 必须是类升

android - 访问 asp.net 网络服务

java - 在提交时传递自定义对象

android - 如何允许电子邮件 ID 在 firebase 中接收 OTP 以进行身份​​验证

java - 检查一个字母是否在一个字符串(单词)中,它在什么位置?

java - (为什么)Tomcat/Java 在 Linux 上比在 Windows 上表现更好?

android - StackLayout中RelativeLayout的宽度计算