1

我为平板电脑应用程序提供了以下布局结构:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="false" >

<LinearLayout
    android:id="@+id/placeholderForLeftFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false" >

    <RelativeLayout
        android:id="@+id/placeholderFragmentHomeScreen"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="32" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/dummy"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="69"
        android:background="#0000" >
    </RelativeLayout>
</LinearLayout>


<LinearLayout
    android:id="@+id/mainLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:clipChildren="false" >

    <RelativeLayout
        android:id="@+id/invisbleRelativeLayout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="32"
        android:background="#0000" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/placeholderFragmentHotelResultList"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="42"
        android:background="#F0FFFF" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/placeholderFragmentHotelDetailScreen"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="26" >
    </RelativeLayout>
</LinearLayout>

第一个 LinearLayout 仅在左侧包含一个片段并且不可移动。第二个 LinearLayout 的第一个位置有一个不可见的元素,当我向左滑动另外两个 R.Layouts 时我会减少它,当我向后滑动时会增加。中间的 RelativeLayout 一直保持他的宽度,我可以在第一个 LinearLayout 上滑动第二个和第三个。实际上,第二个和第三个 R.Layout 应该具有相同的宽度,但第三个应该仅在屏幕边框处可见到 26%。

我现在想要做的是,第三个 R.Layout 的宽度与第二个从一开始(在应用程序启动后)的宽度相同,并且他的位置是屏幕外的一半。我试图做的是,创建一个布局,其宽度来自所有三个 R.Layouts 的总和并将布局放入其中,但它不起作用 - 我只看到第一个 LinearLayout 中的元素。当我在上面的代码中使用 weight 属性时,第三个 R.Lay 被拉伸,这正是我试图避免的行为。当我将Margin_right 设置为负值时,什么也没有发生。

我感谢任何想法和想法。谢谢!

4

1 回答 1

0

我发现以下解决方案对我来说很好。

<LinearLayout
    android:id="@+id/mainLinearLayout"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:clipChildren="false"
    android:weightSum="100" >

    <RelativeLayout
        android:id="@+id/invisbleRelativeLayout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="32"
        android:background="#0000" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/placeholder1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="43"
        android:background="#F0FFFF" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/placeholder2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="43"
        android:background="#F0FFFF" >
    </RelativeLayout>
</LinearLayout>

请注意,三个布局的权重之和大于顶部 LinearLayout 中的 100。

于 2012-09-17T14:00:34.983 回答