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>