Im a junior developer in android.I created the widgets. I want to add vertical scroll bar in my widget.How can i do this? Thanks.
My Widget Codes:
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 file:
<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>
Option - 1: Use ScrollView
to make the view Scrollable
<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>
Option - 2: Just set the scrollbars
property in your TextView
in layout.xml
android:scrollbars = "vertical"
And then set setMovementMethod
to ScrollingMovementMethod
in your code
[appwidget_text].setMovementMethod(new ScrollingMovementMethod());
I solved this problem with single-element listview structure.
I hope helpful for your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.