【发布时间】:2017-07-08 20:34:11
【问题描述】:
我有一个LinearLayout。在里面,我有几个Fragments。我想在另一个Activity 中使用我的顶部Fragment,但保持完全相同的大小。我的问题是,下一个Activity 是RelativeLayout,而android:weightSum 不可用。如何保持我的尺寸从 LinearLayout 到 RelativeLayout?
<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>
解决方案: 我使用了如下建议的 RelativeLayout Percentages。我想指出,我必须添加一些东西才能使其正常工作,包括:
在 Gradle 中:
compile 'com.android.support:percent:23.3.0'
在 XML 中:
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
希望这对下一个人有帮助:)
【问题讨论】:
-
RelativeLayout的Acitivity的邮政编码 -
现在 Activity 只有一个没有任何内容的 RelativeLayout,因为我无法获得片段的特定大小。它将与 LinearLayout 几乎相同。将 LL 切换为 RL 不会有任何问题,但我试图保持屏幕尺寸之间的比例。