如何为Android小部件制作水平视图滚动条?

如何为Android小部件制作水平视图滚动条?,android,eclipse,android-layout,android-widget,Android,Eclipse,Android Layout,Android Widget,基本上,我正在制作一个android小部件,根据用户的滑动方向,视图从左到右、从右到左滚动 下面是我的mail.xml。有人能建议我如何制作水平卷轴吗?当我更改此布局时,它会显示:加载小部件时出现问题。请给我一个解决方案 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_wid

基本上,我正在制作一个
android
小部件,根据用户的滑动方向,视图从左到右、从右到左滚动

下面是我的
mail.xml
。有人能建议我如何制作水平卷轴吗?当我更改此布局时,它会显示:
加载小部件时出现问题
。请给我一个解决方案

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp"
android:background="@drawable/background"
android:gravity="center"
android:orientation="vertical" >

    <TextView
        android:id="@+id/widget1label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/widget1txt"
        android:textAppearance="?android:attr/textAppearanceLarge" />


</LinearLayout>

我认为
水平滚动视图
就是您要找的。只需简单地包装要滚动的元素,它就可以工作。


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/heading_title"
    />

<ScrollView 
    android:id="@+id/layout" 
    android:layout_height="fill_parent"     
    android:layout_alignParentBottom="true"     
    android:scrollbars="horizontal|vertical" 
    android:layout_width="fill_parent"     
    android:layout_marginTop="5dip"     
    android:scrollbarStyle="outsideInset"
    android:fillViewport="true"> 

<HorizontalScrollView 
    android:id="@+id/horizontalView" 
    android:layout_height="fill_parent"     
    android:scrollbars="horizontal|vertical" 
    android:layout_width="wrap_content"     
    android:layout_marginTop="5dip">



............Place all your layouts, views, such as linear layouts, table layouts, etc, that are needed for your app. Note that the TextView for heading/title (see above) will be outside the scrollview, so it will always stay visible at the top. Remove this if not needed, or add there more views as needed .............



    </HorizontalScrollView> 
</ScrollView>
放置应用程序所需的所有布局、视图,如线性布局、表格布局等。请注意,标题/标题的文本视图(见上文)将位于scrollview之外,因此它将始终在顶部可见。如果不需要,请删除此视图,或者根据需要添加更多视图。。。。。。。。。。。。。

因此答案是:如果您熟悉应用程序小部件布局,那么创建应用程序小部件布局很简单。但是,您必须知道,应用程序小部件布局是基于RemoteView的,RemoteView不支持所有类型的布局或视图小部件

RemoteView对象(以及相应的应用程序小部件)可以支持以下布局类:

FrameLayout
LinearLayout
RelativeLayout
GridLayout
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper
以及以下小部件类:

FrameLayout
LinearLayout
RelativeLayout
GridLayout
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper

您好,谢谢您的回复事实上我这样做了,但正如我前面提到的那样,它在小部件加载上给我带来了错误。有什么问题吗?我尝试了这个Hi-Abhi,我尝试了两种解决方案,但都不起作用。它说我在xml文件中进行布局时“Srcollview的线性父项没有用”。您好,阿里,请参见线性布局仅在单个视图中工作。因此,将scrollview设置为父/根。。删除布局代码。然后检查一次,你是否关闭了布局标签??我将scrollview放到根目录下,然后在启动应用程序时再次测试其给出的错误。“加载小部件时出现问题”