赞
踩
我想在RelativeLayout中以编程方式对齐TextViews . 像这样:
Title of row
Other views -- TextView 1 TextView2 TextView3 etc.. -- other views
所以我有一个foreach,它是以编程方式添加我的textViews的循环 . 这是我的预告:
for(DocumentField d: listOfFields){
if(d.isHighlighted()){
TextView txt = new TextView(getApplicationContext());
txt.setBackgroundDrawable(getResources().getDrawable(R.drawable.shp_round_corners));
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
params.setMargins(10, 0, 0, 0);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
txt.setLayoutParams(params);
txt.setTag("field");
GradientDrawable drawable = (GradientDrawable)txt.getBackground();
if(usedcolorMap.get(code) != null)
drawable.setColor(usedcolorMap.get(code));
if(d.isNumeric())
txt.setText(d.convertedNumber());
else if(d.isText())
txt.setText(d.getTextValue());
else if(d.isDate())
txt.setText(d.convertedDate());
String text = txt.getText().toString();
if(metrics.densityDpi <= DisplayMetrics.DENSITY_MEDIUM){
if(text.length() > 8)
text = text.substring(0, 8).trim() + "...";
}else if(text.length() > 15){
text = text.substring(0, 15).trim() + "...";
}
txt.setTextColor(Color.WHITE);
txt.setTextSize(12);
txt.setTypeface(null, Typeface.BOLD);
txt.setText(text);
ll.addView(txt);
}
}
和xml:
android:layout_width="wrap_content"
android:layout_marginLeft="3dip"
android:layout_height="20dip"
android:id="@+id/doc_fields"
android:tag="ll"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/doc_tag"
android:orientation="horizontal" >
此代码的结果是textViews重叠 . 我想仅使用相对布局来获得更好的性能
我试过这个规则:
if(idOltText != 0)
params.addRule(RelativeLayout.LEFT_OF, idOltText);
但仍然没有工作..
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。