如何旋转android小部件文本?还有一些我不明白的事情

发布于 2024-12-29 09:22:13 字数 1479 浏览 2 评论 0原文

我试图让我的 Android 小部件内的文本框/文本视图旋转,但我不知道如何操作。

问题:

  1. 如何使里面的文本旋转,就像小部件从左到右一样? 2.remoteViews.setTextViewText
  2. 如何与动画一起使用?

这是我尝试过的小部件示例代码,想要使文本旋转。

public class WatchWidget extends AppWidgetProvider{
@Override
public void onUpdate(   Context context, AppWidgetManager appWidgetManager,
                        int[] appWidgetIds ) 
{
    DateFormat format = SimpleDateFormat.getTimeInstance( SimpleDateFormat.MEDIUM, Locale.getDefault() );

    RemoteViews remoteViews = new RemoteViews( context.getPackageName(), R.layout.main );
    ComponentName watchWidget = new ComponentName( context, WatchWidget.class );    

    remoteViews.setTextViewText( R.id.widget_textview, "Time = " + format.format( new Date()));

    appWidgetManager.updateAppWidget( watchWidget, remoteViews );

}
}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="300dp"
android:layout_height="72dp"
android:layout_margin="8dip"
android:background="@drawable/background"
android:orientation="horizontal" >

<TextView
    android:id="@+id/widget_textview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="4dip"
    android:layout_weight="16"
    android:gravity="center_vertical|center_horizontal"
    android:textColor="@android:color/black"
    android:textSize="8pt" />

</LinearLayout>

I am try to make the textbox/textview inside my android widget rotate, but i dont know how to.

Questions:

  1. how to make the text inside rotate, like from left to right for widget?
    2.
  2. remoteViews.setTextViewText how can this work with animation?

Here is the widget example code I played around and wanted to make the text rotate.

public class WatchWidget extends AppWidgetProvider{
@Override
public void onUpdate(   Context context, AppWidgetManager appWidgetManager,
                        int[] appWidgetIds ) 
{
    DateFormat format = SimpleDateFormat.getTimeInstance( SimpleDateFormat.MEDIUM, Locale.getDefault() );

    RemoteViews remoteViews = new RemoteViews( context.getPackageName(), R.layout.main );
    ComponentName watchWidget = new ComponentName( context, WatchWidget.class );    

    remoteViews.setTextViewText( R.id.widget_textview, "Time = " + format.format( new Date()));

    appWidgetManager.updateAppWidget( watchWidget, remoteViews );

}
}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="300dp"
android:layout_height="72dp"
android:layout_margin="8dip"
android:background="@drawable/background"
android:orientation="horizontal" >

<TextView
    android:id="@+id/widget_textview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="4dip"
    android:layout_weight="16"
    android:gravity="center_vertical|center_horizontal"
    android:textColor="@android:color/black"
    android:textSize="8pt" />

</LinearLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文