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)
就能看到成功绘制了。?
?
?
推荐阅读
热点文章
android中Bitmap用法(显示,保存,缩放,旋转)实例分析
12
android 仿微信聊天气泡效果实现思路
1
Android的尺度,drawable-xxxxxxx
2
Codeforces Round #656 (Div. 3) (C、D题)
1
Android之handler异步消息处理机制解析
6
GridView中图片显示出现上下间距过大,左右图片显示类似瀑布流的问题
0
AsyncTask的简单使用
5
两个简单Fragment之间的通信(三种方式)
18
uboot修改设置boot参数命令
41
android中实现从相册中一次性获取多张图片与拍照,并将选中的图片显示出来
2