[英]How can ı add vertical scroll bar in widget?
我是 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>
选项 - 1:使用ScrollView
使视图可滚动
<ScrollView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorMyBlue"
android:padding="@dimen/widget_margin">
<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>
</ScrollView>
选项 - 2:只需在TextView
中的layout.xml
中设置scrollbars
属性
android:scrollbars = "vertical"
然后在您的代码中将setMovementMethod
设置为ScrollingMovementMethod
[appwidget_text].setMovementMethod(new ScrollingMovementMethod());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.