2013-07-18 38 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