Closed LankyBin-lb closed 2 years ago
不在XML里写布局,而是在actuvuty中动态布局: addTextView(String text, int x, int y, int width, int height):
LinearLayout frameLayout = new LinearLayout(mContext); frameLayout.setX(x); frameLayout.setY(y); frameLayout.setLayoutParams(new LayoutParams(width, height)); ScrollTextView scrollTextView = new ScrollTextView(mContext); scrollTextView.setX(x); scrollTextView.setY(y); scrollTextView.setScaleX(width); scrollTextView.setScaleY(height); // scrollTextView.setMinimumWidth(width); // scrollTextView.setMinimumHeight(height); scrollTextView.setScrollForever(true); scrollTextView.setSpeed(4); scrollTextView.setText(text); frameLayout.addView(scrollTextView); root_layout.addView(frameLayout); 走到.setText的时候回报空引用: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'float android.graphics.Paint.measureText(java.lang.String)' on a null object reference
我想是支持的,https://patents.google.com/patent/CN103336691A/zh 这个专利就包含这种方式
不在XML里写布局,而是在actuvuty中动态布局: addTextView(String text, int x, int y, int width, int height):
LinearLayout frameLayout = new LinearLayout(mContext); frameLayout.setX(x); frameLayout.setY(y); frameLayout.setLayoutParams(new LayoutParams(width, height)); ScrollTextView scrollTextView = new ScrollTextView(mContext); scrollTextView.setX(x); scrollTextView.setY(y); scrollTextView.setScaleX(width); scrollTextView.setScaleY(height); // scrollTextView.setMinimumWidth(width); // scrollTextView.setMinimumHeight(height); scrollTextView.setScrollForever(true); scrollTextView.setSpeed(4); scrollTextView.setText(text); frameLayout.addView(scrollTextView); root_layout.addView(frameLayout); 走到.setText的时候回报空引用: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'float android.graphics.Paint.measureText(java.lang.String)' on a null object reference