Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 垂直堆叠两个安卓碎片_Android_Android Fragments - Fatal编程技术网

Android 垂直堆叠两个安卓碎片

Android 垂直堆叠两个安卓碎片,android,android-fragments,Android,Android Fragments,我正在为计算器设计一个UI,但我想为同时显示的UI的不同部分使用不同的片段。但是,我希望在相对布局中垂直堆叠片段 然而,我希望fragment1的大小由控件的大小设置,而不是硬编码一些高度。这样我就可以轻松地更改fragment1的控件,而不用担心它的总高度 我尝试了一个相对的布局,但是我不能让fragment2显示在fragment1下面。这是我试过的 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:

我正在为计算器设计一个UI,但我想为同时显示的UI的不同部分使用不同的片段。但是,我希望在相对布局中垂直堆叠片段

然而,我希望fragment1的大小由控件的大小设置,而不是硬编码一些高度。这样我就可以轻松地更改fragment1的控件,而不用担心它的总高度

我尝试了一个相对的布局,但是我不能让fragment2显示在fragment1下面。这是我试过的

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/side_panel"
        android:layout_width="match_parent"
        <!--this sort of sucks (don't want hadcode 100dp, I want the controls I put in here to resize this automatically.-->
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        class="com.guitarv.www.ndigitcalc.SidePanelFragment">
    </fragment>

    <fragment
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/main_panel"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_below="@+id/side_panel"
        class="com.guitarv.www.ndigitcalc.MainPanelFragment">
    </fragment>

</RelativeLayout>

android:layout\u height=“100dp”
android:layout\u alignParentLeft=“true”
android:layout\u alignParentTop=“true”
class=“com.guitarv.www.ndigtical.SidePanelFragment”
对如何使这项工作起作用有什么建议吗


谢谢

使用垂直线性布局而不是相对布局。
android:layout\u height=“match\u parent”
是问题所在,请更改为
wrapContent
或使用
LinearLayout