Android 仅显示第一个元素的片段布局(TextView)
我有两个片段,这取决于手机是处于横向模式还是纵向模式。但是,两者都只显示第一个元素,后面没有其他元素,如编辑文本或按钮。有解决办法吗 pm_布局Android 仅显示第一个元素的片段布局(TextView),android,android-fragments,Android,Android Fragments,我有两个片段,这取决于手机是处于横向模式还是纵向模式。但是,两者都只显示第一个元素,后面没有其他元素,如编辑文本或按钮。有解决办法吗 pm_布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android: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
<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_布局中,您有方向=水平的LinearLayout,其子项有宽度匹配父项,因此您应该只在pm_布局中看到第一个TextView,您有方向=水平的LinearLayout,其子项有宽度匹配父项,因此您应该只看到第一个TextView切勿使用px,使用sp作为文本。此外,LM_碎片比PM_碎片重1,这意味着它占用更多空间。没有足够的空间容纳所有可能的内容。永远不要使用px,使用sp作为文本。此外,LM_碎片比PM_碎片重1,这意味着它占用更多空间。没有足够的空间容纳所有可能的东西。谢谢!我犯了这样一个愚蠢的错误--只要堆栈允许,就会标记为正确。谢谢!就我而言,这样一个愚蠢的错误——只要堆栈允许,就会被标记为正确。