我创建了课程customTextView extent TextView
我将textAlignment
设置为中心。
在onMeasure
我更改了textview
宽度。
在该textview之后将对齐更改为left
我使用了this.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
但它没有变成中心
答案 0 :(得分:0)
在您的课程中添加以下代码。
Runnable runnable = new Runnable() {
public void run() {
view.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
}
};
Handler handler = new Handler();
handler.postDelayed(runnable,1000);
答案 1 :(得分:0)
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
ImageView imageView = (ImageView)((Activity) context).findViewById(R.id.list_r);
int imageViewHeight = imageView.getMeasuredWidth();
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
int final_width = parentWidth - 2*imageViewHeight;
this.setMeasuredDimension(final_width, parentHeight);
Runnable runnable = new Runnable() {
public void run() {
view.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
}
};
Handler handler = new Handler();
handler.postDelayed(runnable,1000);
}