Android Xamarin Views 在膨胀后失去属性?
Android Xamarin Views losing properties after Inflating?
我正在尝试在文本上设置图像格式。我可以用边距和其他黑客代码来实现这一点。我宁愿以相对的方式做正确的事。
下面是我在适配器中使用的代码,添加视图并更改文本。
当视图呈现时,视图没有我在 xml 中应用的任何格式。我错过了什么吗?布局膨胀时属性会被擦除吗?
foreach (var ball in message.balls) {
LinearLayout numberholder = new LinearLayout (context);
LayoutInflater inflaterball = (LayoutInflater)context.GetSystemService (Context.LayoutInflaterService);
View vballlayout = inflaterball.Inflate (Resource.Layout.ball, null);
if (ball != null) {
TextView tv = vballlayout.FindViewById<TextView> (Resource.Id.textball);
tv.Text = ball.number;
}
}
这是 imageview/textview 在进入视图之前的样子。
之后
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ball"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:id="@+id/bgball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/yellowball" />
<TextView
android:id="@+id/textball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20"
android:layout_alignLeft="@id/bgball"
android:layout_alignTop="@id/bgball"
android:layout_alignRight="@id/bgball"
android:layout_alignBottom="@id/bgball"
android:gravity="center"
android:textStyle="bold"
android:textColor="@android:color/black" />
更改目标版本可修复新手机的问题
android:targetSdkVersion="18"
我正在尝试在文本上设置图像格式。我可以用边距和其他黑客代码来实现这一点。我宁愿以相对的方式做正确的事。
下面是我在适配器中使用的代码,添加视图并更改文本。
当视图呈现时,视图没有我在 xml 中应用的任何格式。我错过了什么吗?布局膨胀时属性会被擦除吗?
foreach (var ball in message.balls) {
LinearLayout numberholder = new LinearLayout (context);
LayoutInflater inflaterball = (LayoutInflater)context.GetSystemService (Context.LayoutInflaterService);
View vballlayout = inflaterball.Inflate (Resource.Layout.ball, null);
if (ball != null) {
TextView tv = vballlayout.FindViewById<TextView> (Resource.Id.textball);
tv.Text = ball.number;
}
}
这是 imageview/textview 在进入视图之前的样子。
之后
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ball"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:id="@+id/bgball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/yellowball" />
<TextView
android:id="@+id/textball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20"
android:layout_alignLeft="@id/bgball"
android:layout_alignTop="@id/bgball"
android:layout_alignRight="@id/bgball"
android:layout_alignBottom="@id/bgball"
android:gravity="center"
android:textStyle="bold"
android:textColor="@android:color/black" />
更改目标版本可修复新手机的问题
android:targetSdkVersion="18"