TextView text= new TextView(this);
如何把text设置成以下样式?
<TextView
     android:layout_width="wrap_content"
     android:layout_height="22dp"
     android:layout_weight="9"
     android:textSize="13dp"
     android:gravity="center_vertical"
     android:layout_marginLeft="10dp"
     android:textColor="#000000" />谢谢。

解决方案 »

  1.   

    TextView text= new TextView(this);
    这行代码是什么意思,this是什么东西。
      

  2.   

    TextView text= new TextView(this);
    text.setWidth("22dip");
    text.setHeight("10dip");
    后面的楼主自己写吧,有问题接着问!
      

  3.   

    这个我也会啊,问题是layout_weight、layout_marginLeft那些怎么设置啊
      

  4.   

    xml文件可以实现,为何要这么写呢
      

  5.   

    应该是:TextView text = new TextView(this);
    text.setLayoutParams(new LayoutParams(..........这里写LayoutParams常量));
    xml中的属性大部分可以用代码设置,但建议楼主最好写在xml文件中,避免代码过于混乱!当有很多控件要实现的话,你用代码实现会显得太麻烦,也不友好!别人读你的代码会很困难!但是,有一个好处就是可以动态改变控件的样式!