Java 文本视图在水平布局中不可见

Java 文本视图在水平布局中不可见,java,android,xml,textview,Java,Android,Xml,Textview,我正在做一个关于“大书呆子农场”的教程,现在看来对我来说似乎不起作用。我用他们的代码检查了三次,但都不起作用。XML是一个新的content_quick.XML文件,它位于layout land中,由于“下一步”按钮显示在正确的位置,因此部分工作正常 目标是: 但我的应用程序看起来像这样: 但在垂直方向上,它确实起作用: 水平方向的XML如下所示: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:androi

我正在做一个关于“大书呆子农场”的教程,现在看来对我来说似乎不起作用。我用他们的代码检查了三次,但都不起作用。XML是一个新的content_quick.XML文件,它位于layout land中,由于“下一步”按钮显示在正确的位置,因此部分工作正常

目标是:

但我的应用程序看起来像这样:

但在垂直方向上,它确实起作用:

水平方向的XML如下所示:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/question_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:padding="24dp" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:orientation="horizontal">

        <Button
            android:id="@+id/true_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/true_button"/>

        <Button
            android:id="@+id/false_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/false_button"/>

    </LinearLayout>

    <Button
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next_button"
        android:drawableRight="@drawable/arrow_right"
        android:layout_gravity="bottom|right"
        android:drawablePadding="4dp"/>

</FrameLayout>    

我在android 6和6.0.1上,在我的手机和模拟器上测试了这个。两者都提供了错误的样式,并放弃了TextView。这里出了什么问题?

尝试将android:text=“test”放在文本视图中,以便查看它是否显示。

框架布局允许沿Z轴放置。它被设计成在屏幕上屏蔽一个区域来显示单个项目。通常,FrameLayout应用于保存单个子视图,因为在子视图不重叠的情况下,很难以可扩展到不同屏幕大小的方式组织子视图

对于您的问题,您应该切换到相对/线性布局

我使用
相对布局
进行了
布局
应用了一些更改。使用
相对布局
而不是
帧布局

默认情况下,
/res/layout
中的布局同时应用于纵向和横向

例如,如果你有

/res/layout/main.xml

您可以添加一个新文件夹
/res/layout land
,将
main.xml
复制到其中并进行必要的调整

请参考此项。

<?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:id="@+id/question_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:text="The pacific ocean is larger than specific ocean."
        android:textColor="#000" />

    <LinearLayout
        android:id="@+id/LL1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/question_text_view"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginTop="5dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/true_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="True" />

        <Button
            android:id="@+id/false_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="False" />

    </LinearLayout>

    <Button
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:drawablePadding="4dp"
        android:drawableRight="@mipmap/ic_launcher"
        android:text="Next Button" />

</RelativeLayout>

这里是
纵向屏幕

这里是
横向屏幕


共享代码,您可以在其中将值设置为textView(R.id.question\u text\u view),以便删除测试用例
android:padding=“24dp”
@IntelliJAmiya使用android:configChanges=“orientation”是一种糟糕的方式。阅读更多信息我建议您使用RelativeLayout作为父包装器,FrameLayout应该在您想要覆盖元素的时候使用我没有足够的声誉来添加注释我添加了
android:text=“Test”
,但它没有显示感谢您。但是,如何使用线性布局获得右下角的“下一步”按钮?@DanielsWrath您可以使用
android:gravity=“bottom | right”
中的
linear layout
@jaydroider来实现这一点,但布局的另一部分需要居中。所以我不想把所有的事情都推到右下角。@DanielsWrath检查下面我的答案,这将对你有帮助。@DanielsWrath很高兴它成功了,干杯!!向上投票也谢谢:)。如果我得到15个代表,我会的;)
<?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:id="@+id/question_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:text="The pacific ocean is larger than specific ocean."
        android:textColor="#000" />

    <LinearLayout
        android:id="@+id/LL1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/question_text_view"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginTop="5dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/true_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="True" />

        <Button
            android:id="@+id/false_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="False" />

    </LinearLayout>

    <Button
        android:id="@+id/next_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:drawablePadding="4dp"
        android:drawableRight="@mipmap/ic_launcher"
        android:text="Next Button" />

</RelativeLayout>