用户登录
用户注册

分享至

Android:自定义layout 无法显示

  • 作者: 零116904441
  • 来源: 51数据库
  • 2021-08-28

布局代码引入自定义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抓取看,自定义控件绘制上去了,但是没有效果:?

?

如果是这种情况,就要看自定义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)

就能看到成功绘制了。?

?

?

软件
前端设计
程序设计
Java相关