クラスを作成し、中央customTextView extent TextView
に設定textAlignment
しました。で幅onMeasure
を変えました。textview
その後、テキストビューの変更を左に揃えて使用this.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
しましたが、中央に変更されませんでした
クラスに以下のコードを追加します。
Runnable runnable = new Runnable() {
public void run() {
view.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
}
};
Handler handler = new Handler();
handler.postDelayed(runnable,1000);
このような?
@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);
}