TextViews 未在 gridLayout 中显示 - Android
TextViews not shown in gridLayout - Android
我在将自定义视图添加到 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 在未选中时设置为白色,如果选中则设置为黑色。当它将我的主题更改为默认主题时找到它。
显示 ImageView
是因为您创建了一个以 ImageView
作为元素 (stars = new List<ImageView> ();
) 的列表。如果您想同时显示 ImageView
和 TextView
,我建议您创建一个显示自定义网格对象的自定义 GridView
。可以在此处找到有关如何完成此操作的优秀教程:http://www.learn2crack.com/2014/01/android-custom-gridview.html
显然,在 gridView 和 gridLayout 中,Textview 未选中时设置为白色,选中时设置为黑色。当它将我的主题更改为默认主题时找到它。
我在将自定义视图添加到 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 在未选中时设置为白色,如果选中则设置为黑色。当它将我的主题更改为默认主题时找到它。
显示 ImageView
是因为您创建了一个以 ImageView
作为元素 (stars = new List<ImageView> ();
) 的列表。如果您想同时显示 ImageView
和 TextView
,我建议您创建一个显示自定义网格对象的自定义 GridView
。可以在此处找到有关如何完成此操作的优秀教程:http://www.learn2crack.com/2014/01/android-custom-gridview.html
显然,在 gridView 和 gridLayout 中,Textview 未选中时设置为白色,选中时设置为黑色。当它将我的主题更改为默认主题时找到它。