简体   繁体   English

片段布局仅显示第一个元素(TextView)

[英]Fragment layout only showing first element (TextView)

i have two fragments that show depending on whether the phone is in landscape or portrait mode. 根据手机处于横向还是纵向模式,我会显示两个片段。 however both only show the first element but nothing else after like EditText or Buttons. 但是,两者都只显示第一个元素,而后仅显示EditText或Buttons。 Is there a fix for this? 有解决办法吗?

pm_layout pm_layout

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/portrait_message"
        android:textColor="#000000"
        android:textSize="100px"/>


    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Enter First Time"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Enter Second Time"/>

</LinearLayout>

activity_main.xml activity_main.xml

<LinearLayout 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"
    tools:context=".MainActivity"
    android:orientation="horizontal">

    <fragment
        android:name="com.android.madpracticaltest.LM_Fragment"
        android:id="@+id/lm_fragment"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent"/>

    <fragment
        android:name="com.android.madpracticaltest.PM_Fragment"
        android:id="@+id/pm_fragment"
        android:layout_weight="2"
        android:layout_width="0dp"
        android:layout_height="match_parent"/>

    <Button
        android:id="@+id/button_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"/>

</LinearLayout>

pm_layout ,您的LinearLayoutorientation="horizontal" ,其子项的宽度为match_parent ,因此您应该只看到第一个TextView

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

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