2013-07-18 39 views
0

我正在嘗試創建如下所示的內容。動態調整相對佈局的大小

我可以讓標題正常工作,詞雲看起來像是在右邊。 我從片段調用它。

但我很努力讓兩列工作。

我試圖讓家長像這樣的寬度:

parentLayout = (RelativeLayout) view.findViewById(R.id.ParentLayout); 
parentLayout.getMeasuredWidth() 

它返回0,而parentLayout具有layout_width =「match_parent」

我似乎無法找到教程/範例在這種類型的「視圖」上,或者我用來搜索的關鍵字是錯誤的。

任何輸入讚賞! 在此先感謝!

p.s.我試圖用onMeasure()爲好,但遇到錯誤「必須覆蓋或實現超法」

Page

回答

0

線性佈局真的能夠處理這種類型的佈局就好了。我會用一個安排是這樣的:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="fill_parent" 
     android:background="@color/black" 
     android:orientation="vertical" 
     android:layout_width="fill_parent"> 
     <!-- your header stuff here 

     --> 
     <LinearLayout android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:orientation="horizontal" 
        > 

      <LinearLayout android:id="left picture pane" 
        android:orientation="vertical" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
      > 
       <ImageView android:layout_width="100dp" 
          android:background="@drawable/logo" 
          android:layout_height="50dp" 
          android:layout_margin="10dp" 
          /> 
       <ImageView android:layout_width="100dp" 
          android:background="@drawable/logo" 
          android:layout_height="50dp" 
          android:layout_margin="10dp" 
         /> 
       <ImageView android:layout_width="100dp" 
          android:background="@drawable/logo" 
          android:layout_height="50dp" 
          android:layout_margin="10dp" 
         /> 

      </LinearLayout> 
      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 
        <TextView android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:text="Some Text" 
           android:textColor="#FFFFFF" 
           android:layout_marginTop="20dp" 
           android:layout_marginLeft="10dp" 
           /> 
       <TextView android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="Some Text" 
          android:textColor="#80ffff" 
          android:layout_marginTop="2dp" 
          android:layout_marginLeft="15dp" 
         /> 
           <!-- your fancy lettering in here 
            or you could put them in a relative layout 
            instead of this linear one --> 
      </LinearLayout> 
     </LinearLayout> 
</LinearLayout> 
+0

感謝嗨對於這一點,它的偉大工程。 但我主要關心的是實際上能夠根據屏幕大小或方向動態調整相對於另一個的大小(對不起,我沒有在問題中說清楚)。有什麼建議麼?謝謝!! – Merelda

+0

無論如何,感謝您指引我在正確的方向! – Merelda