android Textview动态设置大小
import android.app.Activity; //import com.travelzen.tdx.BaseActivity; //import com.travelzen.tdx.util.PreferencesUtils; import android.os.Bundle; import android.util.TypedValue; import android.view.MotionEvent; import android.widget.TextView; public class GuideActivity2 extends Activity { private TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); textView = new TextView(this); textView.setText("fuck android "); textView.setTextColor(0xff00ff00); textView.post(new Runnable() { @Override public void run() { System.out.println("xirtam thread id " + Thread.currentThread().getId()); } }); setContentView(textView); } @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { float size = textView.getTextSize(); System.out.println("xirtam " + size); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size - 1); } return super.onTouchEvent(event); } }
直接上代码,不可以直接使用
textView.setTextSize(size-1); //
@param size The scaled pixel size.
这个size是缩放过的像素。