【发布时间】:2022-01-17 17:02:53
【问题描述】:
我有一个edittext,它的宽度设置为wrap-content。我还有一个回收器视图,它的宽度设置为wrap-content。我想让回收站视图宽度等于以编程方式编辑文本宽度。我使用了下面的代码,但它不起作用。从 getMeasuredWidth() 返回的宽度不等于 edittext 宽度。
editText= findViewById(R.id.edit_text);
editText.measure(0, 0);
testRecyclerView= findViewById(R.id.employee_recycler_view);
testRecyclerView.setLayoutManager(new LinearLayoutManager(context));
ViewGroup.LayoutParams layoutParams = testRecyclerView.getLayoutParams();
layoutParams.width = editText.getMeasuredWidth();
testRecyclerView.setLayoutParams(layoutParams);
【问题讨论】:
标签: java android android-recyclerview android-edittext