【问题标题】:what would be the best way to have an Android homescreen widget alternate between textviews?让Android主屏幕小部件在textviews之间交替的最佳方式是什么?
【发布时间】:2011-03-10 20:16:25
【问题描述】:

我正在尝试创建一个主屏幕 Android 小部件,并让它在我将发送给它的两个不同的文本视图之间交替。这可能吗?

【问题讨论】:

  • 更具体一点,您的意思是有 2 个文本视图并交替更新每个文本视图吗?

标签: android text android-widget textview viewflipper


【解决方案1】:

为什么不保持相同的文本视图,只更改显示的文本?

如果你真的必须使用 2 个文本视图,你可以使用 RemoteViews 对象中的 setViewVisibility 方法在 GONE(这意味着不向用户显示,不占用屏幕空间)和 VISIBLE(向用户显示,占用屏幕空间)之间切换)。

【讨论】:

    【解决方案2】:

    您可以使用ViewFlipper 在多个文本视图之间切换,如果您是这个意思。

     <ViewFlipper android:id="@+id/flipper"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:outAnimation="@anim/push_left_out"
                    android:inAnimation="@anim/push_left_in">
    
                    <TextView android:layout_height="fill_parent"
                        android:layout_width="fill_parent" android:padding="16dip"
                        android:id="@+id/txt1" android:textSize="8pt"
                        android:textColor="#ffffffff"
                        android:text="@string/text1"/>
                    <TextView android:layout_height="fill_parent"
                        android:layout_width="fill_parent" android:padding="16dip"
                        android:id="@+id/txt1" android:textSize="8pt"
                        android:textColor="#ffffffff"
                        android:text="@string/text2"/>
    </ViewFlipper>
    
    
    ViewFlipper mFlipper = ((ViewFlipper) this.findViewById(R.id.flipper));
    

    您可以使用按钮事件在文本视图之间切换。

    Button learn_more = (Button) findViewById(R.id.button);
            learn_more.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mFlipper.showNext();
    
                }
            });
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      相关资源
      最近更新 更多