Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.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
Java 在布局之间更改大小_Java_Android_Xml_Fragment - Fatal编程技术网

Java 在布局之间更改大小

Java 在布局之间更改大小,java,android,xml,fragment,Java,Android,Xml,Fragment,我有一个线性布局。在其中,我有一些片段。我想在另一个活动中使用我的顶部片段,但保持大小完全相同。我的问题是,下一个活动是一个RelativeLayout,android:weightSum不可用。如何保持尺寸从线性布局到相对布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_h

我有一个
线性布局
。在其中,我有一些
片段
。我想在另一个
活动中使用我的顶部
片段
,但保持大小完全相同。我的问题是,下一个
活动
是一个
RelativeLayout
android:weightSum
不可用。如何保持尺寸从
线性布局
相对布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/appmenu"
    android:weightSum="6.5">
    <fragment
        android:id="@+id/titlebar"
        class="com.abc.appname.titlebar"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>
    <fragment
        android:id="@+id/mainmenubuttons"
        class="com.abc.appname.mainmenubuttons"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="4.5"/>
    <fragment
        android:id="@+id/bottombar"
        class="com.abc.appname.bottombar"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

</LinearLayout>
在XML中:

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

希望这能帮助下一个家伙:)

使用ParcentRelativeLayout

简单实现

  <android.support.percent.PercentRelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/appmenu"
    >
    <fragment
        android:id="@+id/titlebar"
        class="com.abc.appname.titlebar"
        android:layout_width="fill_parent"

         app:layout_heightPercent="14.5%"/>
    <fragment
        android:id="@+id/mainmenubuttons"
        class="com.abc.appname.mainmenubuttons"
        android:layout_width="fill_parent"

         app:layout_heightPercent="69%"/>
    <fragment
        android:id="@+id/bottombar"
        class="com.abc.appname.bottombar"
        android:layout_width="fill_parent"

        app:layout_heightPercent="14.5%"/>

</LinearLayout>


RelativeLayout
Acitivity
现在活动只有一个RelativeLayout,里面什么都没有,因为我无法获得片段的具体大小。它将与线性布局几乎相同。我将不会有任何问题切换到RL的LL,但我试图保持屏幕大小之间的比例。真棒!谢谢我不知道这个存在。正是我想要的。
  <android.support.percent.PercentRelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/appmenu"
    >
    <fragment
        android:id="@+id/titlebar"
        class="com.abc.appname.titlebar"
        android:layout_width="fill_parent"

         app:layout_heightPercent="14.5%"/>
    <fragment
        android:id="@+id/mainmenubuttons"
        class="com.abc.appname.mainmenubuttons"
        android:layout_width="fill_parent"

         app:layout_heightPercent="69%"/>
    <fragment
        android:id="@+id/bottombar"
        class="com.abc.appname.bottombar"
        android:layout_width="fill_parent"

        app:layout_heightPercent="14.5%"/>

</LinearLayout>