简体   繁体   English

我可以通过编程方式在Widget上更改填充吗?

[英]Can I change the padding programmatically on the Widget?

Can I do something in the public void onUpdate widget method to change the padding of the textView1 on my Widget? 我可以在public void onUpdate小部件方法中做些什么来更改我的小部件上textView1padding吗?

I know how to change textView.Text using - RemoteViews views and views.setTextViewText(R.id.textView1 etc. One man said, I can't use RemoteViews to change the padding on the Widget. So what can I do, and how? I must change the padding programmatically. Padding will be changeable. 我知道如何改变textView.Text使用- RemoteViews viewsviews.setTextViewText(R.id.textView1等一个人说,我不能使用RemoteViews改变padding 。在小部件,以便我能做些什么,以及如何我必须以编程方式更改padding填充将可以更改。

have you tried ? 你有没有尝试过 ?

yourTextView.setPadding(60, 0, 0, 0);

EDIT 编辑

If you are developing for API level > 16, you may use the following method to set a left padding for instance: 如果您正在针对API级别> 16进行开发,则可以使用以下方法设置左填充(例如):

views.setViewPadding(R.id.widget_item, 30, 0, 0, 0); 

change the 30 value to whatever you want 将30的值更改为您想要的任何值

EDIT 2 编辑2

Take this info 获取此信息

You cannot do this in lower SDK . 您不能在较低的SDK中执行此操作。 If you look at the android source the setPadding method is not marked with "@RemotableViewMethod" which allows it's value to be set by the RemoteViews object. 如果您查看android源代码,则setPadding方法未标记为“ @RemotableViewMethod”,这允许它的值由RemoteViews对象设置。 The only hack we found was to use a different layout. 我们发现的唯一技巧是使用不同的布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM