Android AppWidget 大小
我正在 Android 上创建一些应用程序小部件。我还想重新使用应用程序小部件的布局,以便我可以在我的活动中进行控件,使其看起来相同。
因此,工作正常,我遇到的问题是尺寸,我希望得到相同的尺寸。
这是小部件 xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="72dp" android:initialLayout="@layout/sitewidget"
android:minWidth="146dp" android:updatePeriodMillis="60000"
android:configure="com.leaflabs.jaws_editor.SiteWidgetConfigure">
</appwidget-provider>
,您可以看到应用程序小部件的大小与控件大小不完全相同。
问题是我怎样才能得到同样的结果。我在控制向量中指定了以下内容以获得相同的大小,但它不正确
Resources r = context.getResources();
float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
146, r.getDisplayMetrics());
float height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
72, r.getDisplayMetrics());
setLayoutParams(new LinearLayout.LayoutParams((int) width, (int) height));
i am creating a few appwidgets on android. I would also like to resuse the layouts of the appwidgets so i can make controls in my activities so it looks the same.
So that working fine the problem i have is the sizes I would like to get it the same size.
Here is the widget xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="72dp" android:initialLayout="@layout/sitewidget"
android:minWidth="146dp" android:updatePeriodMillis="60000"
android:configure="com.leaflabs.jaws_editor.SiteWidgetConfigure">
</appwidget-provider>
as you can see the appwidget size is not exacly the same size as the controls size.
The question is how do i get it the same. I specified in the control ctor the following to get it the same size but its not correct
Resources r = context.getResources();
float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
146, r.getDisplayMetrics());
float height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
72, r.getDisplayMetrics());
setLayoutParams(new LinearLayout.LayoutParams((int) width, (int) height));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 appwidget 的根布局设置为 FrameLayout (只是一个示例),并且
将您的控件作为其子控件放置在 LinearLayout 中。然后指定 LinearLayout 的大小。
appwidget-provider 中的尺寸不适用于确切的尺寸。
Set the appwidget's root layout to a FrameLayout (just an example), and
place your control in a LinearLayout as a child of it. Then specify your size to that LinearLayout.
The dimensions in the appwidget-provider dont apply to the exact size.