【发布时间】:2012-09-16 18:12:12
【问题描述】:
我正在编写一个小部件。当有人点击小部件按钮时,手电筒正在打开。如果再次单击小部件按钮,手电筒将关闭。我写了一个小应用程序,它可以工作,因为我的布局 xml 文件中有一个表面视图。在我的小部件 xml 上不起作用。
这是我的 widget_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<SurfaceView
android:id="@+id/surface"
android:layout_width="1dp"
android:layout_height="1dp" />
<ImageButton
android:id="@+id/button"
android:src="@drawable/off"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:scaleType="center"/>
</FrameLayout>
在开发者页面上,有一段文字:
http://developer.android.com/guide/topics/appwidgets/index.html
A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
FrameLayout
LinearLayout
RelativeLayout
GridLayout
And the following widget classes:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper
所以我的小部件按钮将永远无法使用,因为我无法使用表面视图。
【问题讨论】:
-
如何在 widget_layout.xml 中添加 Surface View?所以它适用于小部件按钮。
-
user1205415,没有办法做到。 RemoteViews 只接受一组严格定义的视图。你得等待未来的 Android 版本,希望 SurfaceView 能进入这个集合。
标签: android widget surfaceview flashlight