【发布时间】:2020-02-22 13:06:08
【问题描述】:
我是 android 的初级开发人员。我创建了小部件。我想在我的小部件中添加垂直滚动条。我该怎么做?谢谢。
我的小部件代码:
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
int id = 0;
if (MyNotesWidgetActivity.widgetProcess == "create") {
id = CustomAdapter.cid;
} else{
id = CustomAdapter.uid;
}
DataSource dataSource = new DataSource(context);
dataSource.open();
String content = dataSource.getNote(id);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_notes_widget);
views.setTextViewText(R.id.appwidget_text, content);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
xml 文件:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorMyBlue"
android:padding="@dimen/widget_margin"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/appwidget_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="8dp"
android:background="@color/colorMyBlue"
android:contentDescription="@string/appwidget_text"
android:text="@string/add_widget"
android:textColor="#ffffff"
android:textSize="24sp"
android:textStyle="bold|italic" />
</LinearLayout>
【问题讨论】:
-
那你有什么问题?
-
我正在从用户添加的笔记中获取小部件内容。太长的内容不适合小部件。并非所有内容都可见。所以我想给小部件添加一个滚动条。
标签: java android android-layout android-widget scrollbar