0

I've created my own ViewGroup with the aim to evenly distribute 4 elements in its area.

The ViewGroup itself is set to match_parent in both width and height with a TextView above it:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/relativeLayout2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/relativeLayout"
    android:paddingBottom="16"
    android:paddingLeft="16"
    android:paddingRight="16"
    android:paddingTop="16">

    <TextView
        android:id="@+id/title_actions"
        style="@style/h2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/title_dashboard"
        android:textColor="@color/colorAccent" />

    <app.xenon.sync.layout.dashboard
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/title_actions"
        android:layout_marginTop="16dp">

        <!-- 4 elements here -->

    </app.xenon.sync.layout.dashboard>

</RelativeLayout>

The question at hand is how to get the width of the ViewGroup itself from its own class to then distribute the children. I would assume that this would be done in the onMeasure method, yet after digging through here and the Javadoc I wasn't able to find anything that could help me.

So this is why I found you!

henrikl
  • 479
  • 2
  • 14
  • Yea you can get a view size only after it draws, so you cant do it in onCreate. Probably it will be easier if you dont use xml files. – Nanoc Nov 25 '15 at 15:30
  • So I would, in the java file for the ViewGroup, measure the parent's dimensions, do some math, and size the ViewGroup accordingly? Sounds like a plan! – henrikl Nov 25 '15 at 15:32
  • Yea, its the better way, also i will recommend you taking a look at this: http://stackoverflow.com/questions/29956014/why-should-we-use-xml-layouts – Nanoc Nov 25 '15 at 15:40
  • Thanks a ton, it seems somewhat obvious now that you told me! – henrikl Nov 25 '15 at 20:40

0 Answers0