【发布时间】:2020-12-06 22:12:47
【问题描述】:
我创建了一个图像视图,在它之上我创建了一个文本视图。我的目标是,如果有图像,我想显示我的图像视图,如果没有,我想删除图像视图并显示显示“无图像”的文本视图,这是我的 xml 代码:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Item Image: "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView9"
android:textColor="@android:color/holo_blue_dark"/>
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/imageView1"
android:layout_toRightOf="@id/textView9"/>
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="No Image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView10"
android:layout_toRightOf="@id/textView9"
/>
</RelativeLayout>
这是我的代码:
ImageView imgv = view.FindViewById<ImageView>(Resource.Id.imageView1);
textview10 = view.FindViewById<TextView>(Resource.Id.textView10);
textview10.Visibility = ViewStates.Invisible;
private void Ws_getimg_clrCompleted(object sender, WSitems.getimg_clrCompletedEventArgs e)
{
Byte[] data = e.Result.datab;
if (data != null)
{
MemoryStream mem = new MemoryStream(data);
Android.Graphics.Bitmap originBitmap = BitmapFactory.DecodeStream(mem);
imgv.SetImageBitmap(originBitmap);
}
else
{
imgv.Visibility = ViewStates.Gone;
textview10.Visibility = ViewStates.Visible;
}
}
我从网络服务获取图像。问题是当没有图像但文本视图不可见时,只有图像视图正在消失。为什么?我该怎么办?提前致谢。
【问题讨论】:
标签: xamarin.android textview imageview visibility