2012-09-14 35 views
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設置爲負值時,沒有任何反應。

我很欣賞任何想法和想法。 謝謝!

回答

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。

相關問題