【问题标题】:How to make Horizontal view scroller for Android Widget?如何为 Android Widget 制作水平视图滚动器?
【发布时间】:2014-01-13 10:13:20
【问题描述】:

基本上,我正在制作一个 android 小部件,其视图从左到右和从右到左滚动,具体取决于用户滑动的方向。

下面是我的mail.xml。有人可以建议我如何制作水平滚动条吗?当我更改此布局时,它会显示:Problem loading widget。请建议我一个解决方案。

<?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>

【问题讨论】:

    标签: android eclipse android-layout android-widget


    【解决方案1】:

    我认为HorizontalScrollView 是您正在寻找的。只需将要滚动的元素包裹起来,它就可以工作了。

    【讨论】:

    • 嗨,感谢您的回复,实际上我做到了,但正如我上面提到的,它在小部件加载时给了我错误。可能是什么问题?
    • 我试过这个 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"> ​​ntalScrollView>
    【解决方案2】:
    <?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>
    

    【讨论】:

    • 嗨,Abhi,我尝试了两种解决方案,但都没有工作。在 xml 文件中进行布局时,它说我“Srcollview 的班轮父级无用”。
    • 你好 Ali,看到线性布局只能在单个视图中工作。所以将滚动视图作为父/根..删除布局代码。
    • 并检查一次,你是否关闭了布局标签??
    • 我将滚动视图放到根目录,然后在启动应用程序时再次测试它的错误。“加载小部件时出现问题”
    【解决方案3】:

    所以答案是:如果您熟悉 Layouts,那么创建 App Widget 布局很简单。但是,您必须知道 App Widget 布局基于 RemoteViews,它不支持所有类型的布局或视图小部件。

    RemoteViews 对象(因此,App Widget)可以支持以下布局类:

    FrameLayout
    LinearLayout
    RelativeLayout
    GridLayout
    

    还有以下小部件类:

    AnalogClock
    Button
    Chronometer
    ImageButton
    ImageView
    ProgressBar
    TextView
    ViewFlipper
    ListView
    GridView
    StackView
    AdapterViewFlipper
    

    【讨论】:

      猜你喜欢
      • 2011-11-12
      • 2012-10-05
      • 1970-01-01
      • 1970-01-01
      • 2021-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多