有关Android RecyclerView item中组件的宽高的动态修改的问题
以下是代码:
MainActivity:
recyclerView是一个RecyclerView
recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { UpdaterController controller = mUpdaterService == null ? null : mUpdaterService.getUpdaterController(); if(controller != null && mAdapter != null) { List updates = controller.getUpdates(); for (int i = 0; i < recyclerView.getChildCount(); i++) { UpdateInfo update = updates.get(i); View view = recyclerView.getLayoutManager().findViewByPosition(i); LinearLayout mBtnsLayout = (LinearLayout) view.findViewById(R.id.update_btns); ImageButton mAction = (ImageButton) view.findViewById(R.id.update_action); ImageButton mShowChangelog = (ImageButton) view.findViewById(R.id.show_changelog); CardView mCard = (CardView) view.findViewById(R.id.update_card); Space mBtnsSpace = (Space) view.findViewById(R.id.update_btns_space); OnlineImageView mImageView = view.findViewById(R.id.update_imageView); int btnsHeight = mBtnsLayout.getMeasuredHeight(); int cardHeight = mCard.getMeasuredHeight(); mBtnsLayout.setLayoutParams((LinearLayout.LayoutParams)Utils.getLayoutParams(btnsHeight, btnsHeight, mBtnsLayout)); mImageView.setImageURL(update.getImageUrl()); int w = ((mImageView.getImageHeight() * mImageView.getImageWidth()) == 0 ? 0 : (cardHeight * mImageView.getImageWidth() / mImageView.getImageHeight())); mImageView.setLayoutParams((RelativeLayout.LayoutParams)Utils.getLayoutParams(w, cardHeight, mImageView)); mAction.setLayoutParams((LinearLayout.LayoutParams)Utils.getLayoutParams((int) (btnsHeight * 0.6), (int) (btnsHeight * 0.6), mAction)); mShowChangelog.setLayoutParams((LinearLayout.LayoutParams)Utils.getLayoutParams((int) (btnsHeight * 0.3), (int) (btnsHeight * 0.3), mShowChangelog)); mBtnsSpace.setLayoutParams((LinearLayout.LayoutParams)Utils.getLayoutParams(btnsHeight - mAction.getMeasuredHeight() - mShowChangelog.getMeasuredHeight(), btnsHeight, mBtnsSpace)); mAdapter.notifyItemChanged(i); } recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }});以下是Utils.getLayoutParams函数:
public static ViewGroup.LayoutParams getLayoutParams(int tw, int th, View view) { ViewGroup.LayoutParams params = view.getLayoutParams(); params.width = tw; params.height = th; return params;}Debug发现,在上面的第一个代码块执行完毕后,各个控件的LayoutParams发生了改变,其中的宽高与传入值相符,而在控件中的mMessuredWidth和mMessuredHeight的值却均没有变化,也就是实际显示的宽高并未改变。
这是我的仓库:https://github.com/SF2005/Updater
改了快三天了,也上404小厂的网站查过了,也百度了,没找到解决方案,开发组(欢迎来捧场:exTHmUI)里的大佬也问过了,都不觉得有问题...
希望能得到个解决方案,或者告诉我,你也不觉得有问题,谢谢各位了!!!!
这几天真是烦死我了?? |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|