【问题标题】:Android control widget layoutAndroid 控件小部件布局
【发布时间】:2014-11-21 17:22:57
【问题描述】:

我正在尝试制作一个类似于 android 控件小部件(wlan、蓝牙等的快速设置)中的切换按钮的小部件。

Here's how it looks(@Control 小部件)

有谁知道这个布局是否包含在 android sdk 中,或者如果没有,我如何制作一个像那个布局一样的布局?

我已经尝试了一些东西,但我不知道如何处理底部的笔划。

【问题讨论】:

  • 使用 gimp 或 photoshop 创建您自己的未压制图片和压制图片。按下小部件时加载/设置按下的图像,再次单击小部件时加载未按下的图片/图像?你有你的切换按钮..将是我关于如何运行的第一个想法..
  • 也这么认为,但我认为这不是实现这一目标的最佳方式。我很确定他们是使用可绘制对象做到的。
  • 请告诉我如何将小部件定义为控制小部件?

标签: android android-layout android-widget


【解决方案1】:

关于您的问题,我进行了更深入的搜索。

见:https://developer.android.com/guide/topics/appwidgets/index.html

这些是您可以与 appwidget 一起使用以在布局中实现的类,没有像切换按钮这样的东西,但我认为我们正是 Google 用于“切换按钮”的图像按钮。仔细查看 imagebutton : https://developer.android.com/reference/android/widget/ImageButton.html

然后你会发现它正是你要找的。​​p>

    By default, an ImageButton looks like a regularButton, with the standard button background that changes color during different button states. The image on the surface of the button is defined either by the android:src attribute in the XML element or by thesetImageResource(int) method.

我无法想象仅使用干净的 xml 就能实现如此复杂的布局......

希望现在有帮助!

【讨论】:

  • 感谢您的努力。我知道 ImageButton 控件,但我希望有一个更优雅的解决方案。但似乎除了使用图片之外别无他法。
  • @Stefan 不是。请标记为已接受的答案。但是,这种只有普通 xml 的“复杂”布局对我来说似乎是不可能的。请标记为已接受
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-19
相关资源
最近更新 更多