我正在尝试使用远程视图显示小部件内的列表。滚动工作正常,但最后一个元素无法完全滚动且不完全可见。但如果我完全展开小部件,它会显示最后一个元素。
在我的代码中没有什么特别的,只是在 AppWidgetProvider 中分配适配器。
this.setRemoteAdapter(R.id.widgets_list, intent)
我的 widget_timetable.xml,widget ui 存储在其中:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/widget_body_layout"
style="@style/Widget.AppWidget.AppWidget.Container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/widget_background"
android:orientation="vertical"
android:padding="8dp"
tools:discard="@layout/unused2"
tools:keep="@layout/l_used*_c,@layout/l_used_a,@layout/l_used_b*">
<include layout="@layout/widget_timetable_title_region" />
<include layout="@layout/widget_timetable_list_meetings" />
<ListView
android:id="@+id/widgets_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@android:color/transparent"
android:dividerHeight="2.0sp"
tools:discard="@layout/unused2"
tools:keep="@layout/l_used*_c,@layout/l_used_a,@layout/l_used_b*"
tools:listitem="@layout/widget_item" />
<TextView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Loading..."
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
这是视频:
尝试为ListView设置固定的下边距,它将解决问题!
<ListView
android:id="@+id/widgets_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="15dp"
android:divider="@android:color/transparent"
android:dividerHeight="2.0sp"
tools:discard="@layout/unused2"
tools:keep="@layout/l_used*_c,@layout/l_used_a,@layout/l_used_b*"
tools:listitem="@layout/widget_item" />