我有一個小的側欄片段,我加上行動項目選擇。它有一個固定的寬度,我的願望是,主視圖將全屏顯示,直到行動選項被選中時,它會被稍微壓縮以允許邊欄出現。Android的片段側邊欄
我已經嘗試了很多東西,包括相對的toleftOf/RightOf和各種佈局/寬度組合。除非我使用具有權重的LinearLayout,否則我總是以側欄顯示全屏。半工作LinearLayout重量的問題在於它使用屏幕的百分比,這會在不同的屏幕尺寸上導致不可靠的效果。
有沒有人拉掉類似的東西?
______ _
| | | |
| Main |<-|S|
|______| |_|
目前半使用XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false" >
<FrameLayout
android:id="@+id/frameLayoutImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
</FrameLayout>
<!-- This will initially have no content/collapsed -->
<FrameLayout
android:id="@+id/frameLayoutEdit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|top"
android:layout_marginBottom="40dp"
android:layout_weight="4" >
</FrameLayout>
</LinearLayout>
片段XML(可以是固定的寬度):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout />
<Button />
<Button />
</RelativeLayout>
片段此外:
// This should just push the frame layout the necessary width to display the fragment
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.frameLayoutEdit, xmpFrag);
由於到一些元素的方向我不想疊加。這工作了一些修改。 主要 1. layout_width:0dp 2. layout_weight:1個 邊欄: – Anthony 2013-03-19 04:15:30
(被鎖整理註釋編輯出) 這個工作有一些修改。 主要的FrameLayout 1 layout_weight:1 注:layout_width:0dp需要的重量,但並不能改變什麼 側邊欄的FrameLayout: 1. layout_width:WRAP_CONTENT 2.沒有重量 邊欄: 1. layout_width:300dp 注意:300對你的內容是任意的,wrap_content使它永遠不會顯示 – Anthony 2013-03-19 04:29:55
你的側邊欄是一個自定義視圖嗎?如果是這樣,你應該重寫onMeasure以允許wrap_content工作。 – 2013-03-19 04:40:09