我在相对布局中使用了 MvxBindableGridView,它运行良好。然后我意识到我需要为我的屏幕使用 LinearLayouts 才能在不同的设备上正确缩放。当我更改为 LinearLayout 并运行应用程序时,GridView 为空,调试输出显示一些绑定错误
12-03 16:55:38.363 I/MvxBind ( 2689): 14.25 Failed to create target binding for from ClickCommand to ClickItemSquare
MvxBind:Warning: 14.25 Failed to create target binding for from ClickCommand to ClickItemSquare
12-03 16:55:38.363 I/mono-stdout( 2689): MvxBind:Warning: 14.25 Failed to create target binding for from ClickCommand to ClickItemSquare
有谁知道当它在RelativeLayout中完美运行时为什么会失败?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/xxxxx"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/layoutresults"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textscore"
local:MvxBind="{'Text':{'Path':'Score'}}"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="0000"
android:textColor="#ff60350f"
android:textSize="20dp"
android:layout_x="25dp"
android:layout_y="45dp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="53dp"
android:layout_marginLeft="25dp" />
<TextView
android:id="@+id/layoutstartnewgame"
android:layout_width="100dp"
android:layout_height="65dp"
android:layout_x="109dp"
android:layout_y="23dp"
android:textStyle="bold"
local:MvxBind="{'Click':{'Path':'StartNewGame'}}"
android:layout_centerHorizontal="true"
android:layout_marginTop="27dp" />
<TextView
android:id="@+id/texttime"
local:MvxBind="{'Text':{'Path':'Time'}}"
android:text="00:00"
android:textColor="#ff60350f"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="245dp"
android:layout_y="45dp"
android:textStyle="bold"
android:layout_marginTop="53dp"
android:layout_alignParentRight="true"
android:layout_marginRight="23dp" />
</RelativeLayout>
<cirrious.mvvmcross.binding.android.views.MvxBindableGridView
android:layout_below="@+id/layoutresults"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:numColumns="4"
android:gravity="center"
android:listSelector="#00000000"
local:MvxItemTemplate="@layout/itemimage"
local:MvxBind="{'ItemsSource':{'Path':'Squares'}, 'ClickItemSquare':{'Path':'ClickCommand'}}"
android:layout_marginTop="8dp" />
</RelativeLayout>
改为线性
<?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/xxxxx"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/TabletGameScreen">
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_weight=".1"
android:gravity="center" />
<LinearLayout
android:id="@+id/layoutresults"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".1">
<TextView
android:id="@+id/textscore"
local:MvxBind="{'Text':{'Path':'Score'}}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0000"
android:textColor="#ff60350f"
android:textSize="20dp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:textStyle="bold"
local:MvxBind="{'Click':{'Path':'StartNewGame'}}"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/texttime"
local:MvxBind="{'Text':{'Path':'Time'}}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="00:00"
android:textColor="#ff60350f"
android:textSize="20dp"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:gravity="center_horizontal" />
</LinearLayout>
<cirrious.mvvmcross.binding.android.views.MvxBindableGridView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".8"
android:numColumns="4"
android:gravity="center"
android:listSelector="#00000000"
local:MvxItemTemplate="@layout/itemimage"
local:MvxBind="{'ItemsSource':{'Path':'Squares'}, 'ClickItemSquare':{'Path':'ClickCommand'}}" />
</LinearLayout>