当我将自定义视图添加到GridLayout时,我遇到了这个奇怪的问题。我的自定义视图中的所有文字视图都被隐藏(或者已经消失,不知道),当我点击我的自定义视图时,它们就会出现。
这是我的自定义视图:
public class SequenceVOView : LinearLayout
{
TextView lblTitle;
TextView lblTheme;
TextView lblDeadline;
List<ImageView> stars;
ImageView imgSequenceBadge;
ImageView imgRightArrow;
private QuestionSequenceVO _sequence;
public QuestionSequenceVO Sequence {
get {
return this._sequence;
}
set {
_sequence = value;
}
}
public SequenceVOView (Context context) :
base (context)
{
Initialize ();
}
public SequenceVOView () :
base (Application.Context)
{
Initialize ();
}
public SequenceVOView (Context context, IAttributeSet attrs) :
base (context, attrs)
{
Initialize ();
}
public SequenceVOView (Context context, IAttributeSet attrs, int defStyle) :
base (context, attrs, defStyle)
{
Initialize ();
}
void Initialize ()
{
LayoutInflater inflater = (LayoutInflater)Context.GetSystemService (Context.LayoutInflaterService);
View view = inflater.Inflate (Resource.Layout.SequenceVOFragmentLayout, this);
lblTitle = FindViewById<TextView> (Resource.Id.lblSequenceSubject);
lblTheme = FindViewById<TextView> (Resource.Id.lblSequenceTheme);
lblDeadline = FindViewById<TextView> (Resource.Id.lblDeadline);
stars = new List<ImageView> ();
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar1));
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar2));
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar3));
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar4));
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar5));
foreach (var item in stars) {
item.SetImageResource (Resource.Drawable.difficultyStar);
item.Visibility = ViewStates.Invisible;
}
imgRightArrow = FindViewById<ImageView>(Resource.Id.imgSequenceRightArrow);
imgSequenceBadge = FindViewById<ImageView>(Resource.Id.imgSequenceBadge);
}
public void setData(QuestionSequenceVO sequence){
_sequence = sequence;
lblTitle.Text = sequence.Subject;
lblTheme.Text = sequence.Category;
lblDeadline.Text = sequence.DueDate;
for (int i = 0; i < sequence.Difficulty; i++) {
stars [i].Visibility = ViewStates.Visible;
}
imgRightArrow.SetImageResource (Resource.Drawable.arrowRight);
imgSequenceBadge.SetImageResource (Resource.Drawable.imgVragenreeks);
}
}
奇怪的部分是:我的图像显示正确。任何想法?
修改 显然在gridView和gridLayout中,Textviews在未选中时设置为白色,如果选中则设置为黑色。当它将我的主题改为默认时找到它。
答案 0 :(得分:1)
显然在gridView和gridLayout中,Textviews在未选中时设置为白色,如果选中则设置为黑色。当它将我的主题更改为默认时找到它。
答案 1 :(得分:0)
ImageView
正在显示,因为您创建了一个以ImageView
作为元素(stars = new List<ImageView> ();
)的列表。如果您要同时显示ImageView
和TextView
,我建议您创建一个显示自定义网格对象的自定义GridView
。有关如何完成此操作的优秀教程,请访问:http://www.learn2crack.com/2014/01/android-custom-gridview.html