简书链接:uniappnvue基于安卓原生开发初步认知
文章字数:438,阅读全文大约需要1分钟

1 2 3 4 5 6 7 8 9 10
| <androidspinner text="test123" hint="请输入用户名" :datas="columns" style="width: 750rpx; height: 100rpx;background-color: #0093ff;" /> <androidinput text="test123" hint="请输入用户名" style="width: 750rpx; height: 120rpx;background-color: yellow;" /> <androidinput text="test123" hint="请输入用户名" style="width: 750rpx; height: 110rpx;background-color: red;" /> <button type="primary" @click="clickTest">testAsyncFunc</button> <smarttable :columns="columns" :rows="rows" />
|
在添加view的时候直接
1 2 3 4 5 6 7 8 9 10
| @Override protected TextInputLayout initComponentHostView(Context context) { TextInputLayout textInputLayout = new TextInputLayout(context); textInputLayout.setMinimumHeight(DensityUtils.dp2px(context, 30)); edittext = new TextInputEditText(context); edittext.setText("hello"); textInputLayout.addView(edittext, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); Toast.makeText(context, "hello androidinput", Toast.LENGTH_SHORT).show(); return textInputLayout; }
|
而他的高度,是不能通过java这边修改的,必须通过 nvue这边指定宽高样式,否则默认不可见,如果同时设置了宽高之后又设定了高度wrap_content 你会发现一个问题,比原来高度似乎要高一些,如果不指定高度,则会发现出现重叠,故可以判断,他一般情况是framelayout作为布局排版的,因此不应该在java 原生这边控制 设置 宽高 或match_parent wrap_conent
, nvue是不支持的
就算你设置也会产生一些兼容问题,比如重叠。。
感兴趣的朋友可以添加代码然后match_parent="true"
来控制测试效果,
1 2 3 4 5 6 7 8 9
| @UniComponentProp(name = "match_parent") public void match_parent(boolean match_parent) { if (match_parent) { getHostView().getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT; // getHostView().getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT; getHostView().setLayoutParams(getHostView().getLayoutParams()); } }
|
总结:nvue界面中原生控件必须指定宽高。