MVVMCross - MvxGridView не переносит высоту содержимого - PullRequest
0 голосов
/ 28 июня 2018

Я разрабатываю приложение для Android с использованием Xamarin и MVVM Cross. И я пытаюсь загрузить список двух меток в MvxGridView.

Control_List.axml

<?xml version="1.0" encoding="utf-8"?>
<MvxLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<MvxGridView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:numColumns="auto_fit"
    android:verticalSpacing="5dp"
    android:horizontalSpacing="5dp"
    android:stretchMode="columnWidth"
    android:choiceMode="none"
    local:MvxBind="ItemsSource List"
    local:MvxItemTemplate="@layout/list_item" />
</MvxLinearLayout>

и List_item.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:gravity="center_vertical">
<TextView
    android:background="@drawable/roundedshape_calendar_blurb"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:textSize="16dp"
    android:textColor="@color/white"
    android:singleLine="false"
    local:MvxBind="Text Format('{0}: {1}', Key, Value)" />
<View
    android:layout_width="1dp"
    android:layout_height="36dp"
    local:MvxBind="BackgroundColor DarkerThemeColor" />
</LinearLayout>

И вид выглядит так:

MvxGriView layout

И мой вопрос: почему он отображает только одну строку?

Большое спасибо!

1 Ответ

0 голосов
/ 25 октября 2018

Я немного поборолся с этим.

Я нашел простое решение, динамически изменяя высоту сетки:

        var myGrid = _rootView.FindViewById<MvxGridView>(Resource.Id.grid);
        ViewGroup.LayoutParams layoutParams = myGrid .LayoutParameters;
        layoutParams.Height = (ViewModel.Items.Count / myGrid .NumColumns) * _gridRowHeight;
        myGrid.LayoutParameters = layoutParams;
...