Java – dynamically added layout weights on remoteviews

In my widget, I dynamically add items (r.layout.widget_item) to the LinearLayout defined in my main widget layout using the following:

//--  Main widget layout
RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.widget_design);

//--  Add to main layout
RemoteViews newView = new RemoteViews(context.getPackageName(),R.layout.widget_item);
views.addView(R.id.view_container,newView);

My question is, how to dynamically set the "Android: layout_weight" attribute on newview?

Solution

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

The newview in your example is an instance of the remoteviews class. I don't think you can easily set anything beyond what remoteviews provides

newView.setLayoutParams(layoutParams);

The above operation is not valid because it is not part of remoteview

As far as I know... There may be some ways to set and find the size and other layout of remoteviews, but I haven't found it yet

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>