Как я могу добавить вертикальную полосу прокрутки в виджете? - PullRequest
0 голосов
/ 26 октября 2019

Мой английский не очень хороший. Я младший разработчик в 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 Ответ

0 голосов
/ 26 октября 2019

Опция - 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: Просто установите свойство scrollbars в вашемTextView in layout.xml

android:scrollbars = "vertical"

А затем установите setMovementMethod в ScrollingMovementMethod в своем коде

[appwidget_text].setMovementMethod(new ScrollingMovementMethod());
...