java插件相对布局,在相对布局中以编程方式水平对齐视图

我想在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);

但仍然没有工作..

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值