3

I made a custom view which works fine, but when I place the view inside a PercentRelativeLayout the getHeight() method returns 0, Im not initializing the layout_height or layout_width parameters for the view, only the app:layout_hieghtPercent and app:layout_widthPercent.

Even if I set the layout_height the views height is still not initialized.

How do I get the views hieght when its in a PercentRelativeLayout?

Below you can find my xml code:

<android.support.percent.PercentRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background">

<com.cgt.allridepassengerapp.customviews.DigitEditText
        android:id="@+id/et_verify_code"
        android:layout_marginLeft="@dimen/size_30"
        android:layout_marginRight="@dimen/size_30"
        android:background="@android:color/transparent"
        android:imeOptions="actionDone"
        android:maxLength="5"
        app:layout_heightPercent="10%"
        app:layout_marginTopPercent="43.2%"
        app:layout_widthPercent="84.2%">
        <requestFocus/>
    </com.cgt.allridepassengerapp.customviews.DigitEditText>

    </android.support.percent.PercentRelativeLayout>

The onDraw(Context) method:

@Override
    protected void onDraw(Canvas canvas)
    {
        getHeight(); // is 0
    }
Onik
  • 19,396
  • 14
  • 68
  • 91
Arlind Hajredinaj
  • 8,380
  • 3
  • 30
  • 45

0 Answers0