Android:如何向主屏幕小部件添加垂直进度条?
我需要在主屏幕小部件中放置一个垂直滚动条,经过多次搜索,我找不到适用于 API3 及以上版本的便捷解决方案!
我尝试了很多解决方案: - 使用在运行时创建的位图,但在某些显示器上它永远不会达到 100% - patch9 位图,但当进度接近 0 时,滚动条显示完全混乱。 - 将 addView() 与 100 个现有布局一起使用,效果很好,但它仅自 API7 起可用! - 包括所有 100 个布局并一次只显示一个,工作正常,但是将这些布局包括在我的 8 个不同的小部件布局中真是一团糟!
我尝试以编程方式使用权重,但也不可能,还有其他解决方案可以根据百分比调整视图大小吗?
这是我目前使用的一种进度条布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:layout_weight="11" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView android:src="@drawable/scale"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="89" />
</LinearLayout>
I need to put a vertical scroll bar in a home screen widget, and after searching many times, I can't find a convenient solution that works on API3 and above!
I tried many solutions:
- using bitmap created at run-time, but on some displays it never reach 100%
- a patch9 bitmap, but the scroll bar display gets completely messed up when the progress is near 0.
- using the addView() with 100 existing layout and it works great, except it's only available since API7!
- including all 100 layouts and showing only one at a time, work fine, but what a mess to include those in my 8 different widget layouts!
I tried to use the weight programmatically but it's not possible either, any other solution to resize a view based on a %?
Here is one progress bar layout I currently use:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:layout_weight="11" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView android:src="@drawable/scale"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="89" />
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
到目前为止,我发现的唯一解决方案是让所有可能的进度级别准备好在各种 Xml 布局文件中使用。
关于Android API < 7、所有这些都需要包含在单个 xml 布局中并在运行时显示/隐藏,而在 Android API >= 7 上,实际上可以使用 addRemoteView() 以更有效的方式包含所需的布局!
Only solution I found so far is to have all the possible progress levels ready to use in various Xml layout files.
On Android API < 7, all those need to be included in a single xml layout and shown/hidden at run-time, while on Android API >= 7, one can actually use addRemoteView() to include the desired layout in a much more efficient way!
你应该使用 ScrollView!您必须将其放置在布局中。默认情况下,scrollview 是垂直滚动的。如果您想要水平滚动,则必须指定 HorizontalScrollView。希望这有帮助
You should use ScrollView! You must place this within a layout. By default, scrollview is for Vertical Scroll. If you want horizontal scroll you must specify HorizontalScrollView. Hope this helps