Search code examples
androidlayoutandroid-relativelayoutonmeasure

Dynamically resize relative layout


I'm trying to create something that looks like this.

I can sort of get the header working, and the word cloud look-alike stuff on the right. I'm calling it from a Fragment.

But I'm struggling to get the two column thing working.

I tried to get the width of the parent like this:

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

this returns 0, while the parentLayout has layout_width="match_parent"

I can't seem to find tutorials/example on this type of "view", or maybe the keyword I'm using for the search is wrong.

Any input is appreciated!! Thanks in advance!!

p.s. I tried to use onMeasure() as well, but got error "must override or implement a supertype method"

Page


Solution

  • Linear Layouts really can handle this type of layout just fine. I would use an arrangement like this:

    <?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>