我在eclipse代码中显示以下规则。此规则主要负责所有类型的手机。但我的问题是,如果文本更大,就像在这种情况下,它是在框内环绕。有没有办法随着文字的增加自动变大?
TextView rule1
//Add Rule 1
rule1=new ImageView(this);
rule1.setBackgroundResource(R.drawable.rules);
if(w<340)
{
layout_params=new RelativeLayout.LayoutParams(width(310), height(44));
layout_params.leftMargin=width(5);
layout_params.topMargin=height(30);
}else if(w<=500)
{
layout_params=new RelativeLayout.LayoutParams(width(469), height(64));
layout_params.topMargin=height(40);
layout_params.leftMargin=width(6);
}else
{
layout_params=new RelativeLayout.LayoutParams(width(774), height(92));
layout_params.leftMargin=width(13);
layout_params.topMargin=height(60);
}
list_layout.addView(rule1, layout_params);
icon6=new ImageView(this);
icon6.setBackgroundResource(R.drawable.leader);
if(w<340)
{
layout_params=new RelativeLayout.LayoutParams(width(31), height(33));
layout_params.leftMargin=width(12);
layout_params.topMargin=height(39);
}else if(w<=500)
{
layout_params=new RelativeLayout.LayoutParams(width(43), height(44));
layout_params.topMargin=height(52);
layout_params.leftMargin=width(18);
}else
{
layout_params=new RelativeLayout.LayoutParams(width(57), height(60));
layout_params.leftMargin=width(30);
layout_params.topMargin=height(78);
}
list_layout.addView(icon6, layout_params);
rule1 = new TextView(this);
rule1.setText("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
rule1.setTextColor(Color.WHITE);
rule1.setTextSize(18);
rule1.setGravity(Gravity.LEFT);
typeFace=Typeface.createFromAsset(getAssets(), "fonts/HelveticaLTStd-Bold.otf");
rule1.setTypeface(typeFace);
if(w<340)
{
rule1.setTextSize(16);
layout_params=new RelativeLayout.LayoutParams(width(252), height(30));
layout_params.leftMargin=width(40);
layout_params.topMargin=height(39);
}else if(w<=500)
{
layout_params=new RelativeLayout.LayoutParams(width(378), height(40));
layout_params.leftMargin=width(72);
layout_params.topMargin=height(52);
}else
{
layout_params=new RelativeLayout.LayoutParams(width(630), height(60));
layout_params.leftMargin=width(120);
layout_params.topMargin=height(78);
}
rule1.setLayoutParams(layout_params);
list_layout.addView(rule1);
答案 0 :(得分:0)
我认为你想要的是你的<{p> WRAP_CONTENT
RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 150);
如果您愿意,还可以将TextView
设置为singleLine
:
TextView.setSingleLine(true);