GridView适合AppWidget中的行高

时间:2018-12-16 17:21:50

标签: android xml gridview widget android-relativelayout

我正在尝试构建一个在GridView中显示RelativeLayout的应用程序小部件(大学时间表):

widget_layout.xml

 <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
        android:layout_width="match_parent" >

    <GridView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/view_grid"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="false"
        android:layout_alignParentEnd="false"
        android:layout_below="@+id/layout_days"
        android:layout_marginBottom="12dp"
        android:background="@color/border"
        android:horizontalSpacing="2dp"
        android:isScrollContainer="false"
        android:nestedScrollingEnabled="false"
        android:numColumns="5"
        android:padding="2dp"
        android:verticalSpacing="2dp" />

</RelativeLayout>

里面的物品看起来像这样:

lesson_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/lesson_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/ic_notify"
        android:layout_width="14dp"
        android:layout_height="14dp"
        ... />

    <TextView
        android:id="@+id/txt_course"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ...></TextView>

    <TextView
        android:id="@+id/txt_room"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        .../>

    <TextView
        android:id="@+id/txt_prof"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        .../>

</RelativeLayout>

因此,如果应用程序小部件的高度完全适合GridViews的高度,则看起来不错:

Screenshot height fits

(顶部的Mo-Fr栏只是GridView上方的水平LinearLayout)

但是,如果我调整应用程序小部件的高度,则GridView 不会重新调整高度,只需添加滚动条即可。

Screenshot scrollbar

我看到了一些以编程方式扩展GridView的解决方案,但是由于我正在构建 widget ,因此我只能使用RemoteViews方法和XML。 我只是希望GridView的行高适合小部件的高度。

有解决方案吗?

0 个答案:

没有答案
相关问题