1

クラスを作成し、中央customTextView extent TextView に設定textAlignmentしました。で幅onMeasureを変えました。textview

その後、テキストビューの変更を左に揃えて使用this.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); しましたが、中央に変更されませんでした

4

2 に答える 2

0

クラスに以下のコードを追加します。

Runnable runnable = new Runnable() {
            public void run() {
              view.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
            }
   };

Handler handler = new Handler();
handler.postDelayed(runnable,1000);
于 2016-08-01T14:01:44.880 に答える
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);
    }
于 2016-08-01T14:12:18.897 に答える