2012-10-10 17 views
2

我我的FrameLayout的高度設置爲400,但它仍然是64爲什麼我不能強制FrameLayout的高度?

frame_layout.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</FrameLayout> 

MyClass.java

container = (FrameLayout) inflater.inflate(R.layout.frame_layout, scrollFrame, false); 
scrollFrame.addView(container); 
container.setLayoutParams(new 
    ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, 400)); 
Log.d("Output", "FrameLayout Height: " + container.getHeight()); 

輸出

FrameLayout Height: 64 

即使如果我在xml中設置layout_height =「400」,它仍然是64.我認爲這一點與ScrollViews有關。 (儘管我不能使用LinearLayouts,但它們爲我的代碼創建了一系列其他問題。)我希望FrameLayout根據我放置的視圖動態調整大小。 (LinearLayout會自動調整大小,但它會調整到我想要顯示的高度的10倍,這使得ScrollView太大了;然後是定位問題,因爲LinearLayout試圖在我試圖手動排列的視圖上強制位置)。

回答

0

因此,雖然我不能確切回答,爲什麼一個FrameLayout裏無法給出具體的大小,我認爲它有事情做與的FrameLayout的設計。我試圖做的事情最終是濫用了用戶界面以及糟糕的編程設計方法。所以如果你認爲你需要手動調整FrameLayout的大小,問問自己是否真的有必要 - 可能會有更好的方法。

0

嘗試使用weightSums和佈局權重。這是一個佈局,其中兩個幀始終爲屏幕的50%,無論放入其中的內容和高度如何。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      tools:context="com.nimbits.android.HomeActivity" 
      android:weightSum="1.0"> 




<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_above="@+id/progressBar" 
    android:weightSum="1.0" 
    android:orientation="vertical"> 

    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:id="@id/main_frame" 
     android:layout_weight=".5"> 


    </FrameLayout> 

    <FrameLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:id="@id/data_frame" 
     android:layout_weight=".5" 
     android:layout_alignParentEnd="false"> 


    </FrameLayout> 
</LinearLayout> 

+0

嗯,我實際上是試圖將幀的寬度設置爲特定的大小,而不是加權比例。我最終只使用了一個RelativeLayout作爲一個簡單的,可調整大小的框架(並沒有充分利用它的特性)。我最終完全放棄了這個方法。我應該回答我自己的問題。 – Cobryis

相關問題