Layout weight on dynamically added RemoteViews

只谈情不闲聊 提交于 2019-12-04 09:10:24

See: http://developer.android.com/reference/android/widget/RemoteViews.html

newView in your example is an instance of class RemoteViews and I don't think you can easily set anything above and beyond what RemoteViews provides.

newView.setLayoutParams(layoutParams);

The above will not work because it's not part of RemoteViews.

As far as I can see... there may be some round about way of setting and finding dimensions and other layoutParams of RemoteViews, but I haven't found it yet.

first you get the view params like this

layoutParams = newView.getParams();

then edit tham //layoutParams .setThis/setThat all kinds of manipulations you want to do

and then set the new params back to the view

newView.setLayoutParams(layoutParams);

layout_weight is part of the LinearLayout.LayoutParams that you apply to a the LinearLayout, not the LinearLayout itself. There's a constructor that takes a third param representing the layout_weight.

http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html#weight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!