android:lineSpacingExtra="10dp"
有2种方法可以设置TextView文字居中:
一:在xml文件设置: android:gravity="center"
二:在程序中设置: txtTitle.setGravity(Gravity.CENTER);
设置控件居中:
android:layout_gravity="center"是 对textview控件在整个布局中居中,也可以在其父layout中调用设置 android:gravity="center"
程序中也是需要设置其所在控件的父layout,例如:
RelativeLayout.LayoutParams layoutParams=
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
mTextView.setLayoutParams(layoutParams);
edittext 高度随文字的增加高度自动增加
iProfileEdit.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
changeEditTextHeight(s.toString());
}
});
_______________________________________________________________________________________________________________
private void changeEditTextHeight(String s) {
TextView textView = new TextView(PostIssueActivity.this);
textView.setText(s.toString());
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(iProfileEdit.getMeasuredWidth(), MeasureSpec.EXACTLY);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(800, MeasureSpec.AT_MOST);
textView.measure(widthMeasureSpec, heightMeasureSpec);
int textHeight = textView.getMeasuredHeight();
int minHeight = dip2px(80);
LayoutParams layoutParams = iProfileEdit.getLayoutParams();
if (textHeight < minHeight) {
layoutParams.height = minHeight;
} else {
layoutParams.height = textHeight;
}
iProfileEdit.setLayoutParams(layoutParams);
}