Android 在LinearLayout中将两个文本视图居中,文本仅在滚动时显示
我正在尝试将两个文本视图置于线性布局的中心。此LinearLayout嵌套在另一个LinearLayout中,带有ListView元素 我认为我的XML非常正确。我在Adapterclass中动态填充文本视图。 XML:Android 在LinearLayout中将两个文本视图居中,文本仅在滚动时显示,android,listview,scroll,textview,Android,Listview,Scroll,Textview,我正在尝试将两个文本视图置于线性布局的中心。此LinearLayout嵌套在另一个LinearLayout中,带有ListView元素 我认为我的XML非常正确。我在Adapterclass中动态填充文本视图。 XML: 适配器类: /* * Klasse VacatureAdapter */ private class VacatureAdapter extends ArrayAdapter<Vacature>{ private ArrayList<Vacat
适配器类:
/*
* Klasse VacatureAdapter
*/
private class VacatureAdapter extends ArrayAdapter<Vacature>{
private ArrayList<Vacature> vacatures;
public VacatureAdapter(Context context, int textViewResourceId, ArrayList<Vacature> vacatures){
super(context, textViewResourceId, vacatures);
this.vacatures = getArray();
//System.out.println("Array vacatureadapter: " + v);
}
@Override
public View getView(int position, View convertview, ViewGroup parent){
View view = convertview;
if(view==null){
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.vacature_list_item, null);
//view.setBackgroundColor((position % 2) == 1? Color.LTGRAY: Color.WHITE);
}
TextView atlVacatures = (TextView)findViewById(R.id.atlVacatures);
TextView atlVacaturesnr = (TextView)findViewById(R.id.atlVacaturesnummer);
atlVacaturesnr.setText("" + arrVacatures.size());
atlVacatures.setText(" jobs op maat gevonden!");
Vacature vaca = vacatures.get(position);
if(vaca != null){
TextView tvNaam = (TextView) view.findViewById(R.id.vacatureNaam);
TextView tvWerkveld = (TextView) view.findViewById(R.id.vacatureWerkveld);
TextView tvRegio = (TextView) view.findViewById(R.id.vacatureRegio);
if(tvNaam != null){
tvNaam.setText(vaca.getTitel());
if(tvWerkveld != null){
tvWerkveld.setText("Werkveld: " + vaca.getWerkveld());
if(tvRegio!=null){
tvRegio.setText("Regio: "+vaca.getRegio());
}
}
}
}
return view;
}
}
/*
*克拉斯度假酒店
*/
私有类度假适配器扩展ArrayAdapter{
私人ArrayList度假酒店;
public VacationAdapter(上下文上下文、int textViewResourceId、ArrayList Vacations){
super(上下文、textViewResourceId、假期);
this.vacations=getArray();
//System.out.println(“数组休假适配器:+v”);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图=转换视图;
如果(视图==null){
LayoutInflater vi=(LayoutInflater)getSystemService(Context.LAYOUT\u INFLATER\u SERVICE);
视图=vi.充气(R.布局.假期列表项目,空);
//view.setBackgroundColor((位置%2)==1?Color.LTGRAY:Color.WHITE);
}
TextView AtlVacations=(TextView)findViewById(R.id.AtlVacations);
TextView AtlVacuureSNR=(TextView)findViewById(R.id.AtlVacuureSnumer);
AtlVacationsR.setText(“+arrVacations.size());
setText(“jobs op maat gevonden!”);
Vacation vaca=休假。获取(职位);
如果(vaca!=null){
TextView tvNaam=(TextView)view.findViewById(R.id.vacuureNAAM);
TextView tvWerkveld=(TextView)view.findViewById(R.id.vacuurewerkveld);
TextView tvRegio=(TextView)view.findViewById(R.id.vacuureRegio);
如果(tvNaam!=null){
tvNaam.setText(vaca.getitel());
如果(tvWerkveld!=null){
setText(“Werkveld:+vaca.getWerkveld());
如果(tvRegio!=null){
setText(“Regio:+vaca.getRegio());
}
}
}
}
返回视图;
}
}
奇怪的是,如果我的微调器运行,他会正确显示XML中设置的文本,如果微调器停止并填充我的ListView,它只会显示我的数字的一位数,当我滚动一次,他会完整显示我的数字加上第二个TextView。我不太明白出了什么问题,可能有些代码需要放在其他地方?在我关闭对话框后,我将我的setText代码放在我的Runnable方法中,从而解决了我的问题。现在看起来是这样的:
private Runnable returnRes = new Runnable(){
public void run(){
if (arrVacatures.size() == 0){
dialog.dismiss();
}
if(arrVacatures!=null && arrVacatures.size() > 0){
adapter.notifyDataSetChanged();
for(int i= 0; i< arrVacatures.size();i++){
adapter.add(arrVacatures.get(i));
}
dialog.dismiss();
TextView atlVacatures = (TextView)findViewById(R.id.atlVacatures);
TextView atlVacaturesnr = (TextView)findViewById(R.id.atlVacaturesnummer);
atlVacaturesnr.setText("" + arrVacatures.size());
atlVacatures.setText(" jobs op maat gevonden!");
adapter.notifyDataSetChanged();
}
}
};
private Runnable returnRes=new Runnable(){
公开募捐{
如果(arrveatures.size()==0){
dialog.dismise();
}
if(arrveatures!=null&&arrveatures.size()>0){
adapter.notifyDataSetChanged();
对于(int i=0;i
在关闭对话框后,我将setText代码放在我的Runnable方法中,从而解决了我的问题。现在看起来是这样的:
private Runnable returnRes = new Runnable(){
public void run(){
if (arrVacatures.size() == 0){
dialog.dismiss();
}
if(arrVacatures!=null && arrVacatures.size() > 0){
adapter.notifyDataSetChanged();
for(int i= 0; i< arrVacatures.size();i++){
adapter.add(arrVacatures.get(i));
}
dialog.dismiss();
TextView atlVacatures = (TextView)findViewById(R.id.atlVacatures);
TextView atlVacaturesnr = (TextView)findViewById(R.id.atlVacaturesnummer);
atlVacaturesnr.setText("" + arrVacatures.size());
atlVacatures.setText(" jobs op maat gevonden!");
adapter.notifyDataSetChanged();
}
}
};
private Runnable returnRes=new Runnable(){
公开募捐{
如果(arrveatures.size()==0){
dialog.dismise();
}
if(arrveatures!=null&&arrveatures.size()>0){
adapter.notifyDataSetChanged();
对于(int i=0;i
也许您可以提供一个屏幕截图,清楚地显示问题所在。当我无法想象问题是什么时,很难理解。也许你可以包括一个清晰显示问题的屏幕截图。当我无法想象问题是什么时,很难理解。