PercentRelativeLayout childs height为0

时间:2016-03-14 09:42:38

标签: android android-layout android-percentrelativelayout

我创建了一个自定义视图,但是当我将视图放在PercentRelativeLayout内时,getHeight()方法返回0,我没有初始化layout_heightlayout_width视图的参数,只有app:layout_hieghtPercentapp:layout_widthPercent

即使我设置layout_height视图高度仍未初始化。

如何在PercentRelativeLayout

中查看视图

您可以在下面找到我的xml代码:

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

onDraw(Context)方法:

@Override
    protected void onDraw(Canvas canvas)
    {
        getHeight(); // is 0
    }

0 个答案:

没有答案
相关问题