欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android:自定义layout 无法显示

程序员文章站 2022-03-15 10:23:58
布局代码引入自定义layout如下所示:

布局代码引入自定义layout如下所示:

  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/textview_description"
        android:orientation="vertical">

        <com.change.demox.views.edittext.widget.InputEditTextView
            android:id="@+id/user_name"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="20dp" />

        <com.change.demox.views.edittext.widget.InputEditTextView
            android:id="@+id/phone_number"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="20dp" />

    </LinearLayout>

在运行时无法显示,用UI AutoMator抓取看,自定义控件绘制上去了,但是没有效果: 

 

Android:自定义layout 无法显示

如果是这种情况,就要看自定义layout是否是利用inflate的方式动态加载出来的,原写法:
 

    view = View.inflate(context, R.layout.common_edit_text_with_error_message, null)

改为:

    view = View.inflate(context, R.layout.common_edit_text_with_error_message, this)

就能看到成功绘制了。 

 

 

本文地址:https://blog.csdn.net/Crystal_xing/article/details/108845180

相关标签: android UI效果