开发者

Add TextView objects to SurfaceView

Is开发者_开发技巧 it possible to add Textview objects to SurfaceView through canvas or some other way?


You should take a look at drawPostText function.


You can do it by passing a reference of your Activity to your SurfaceView by Application class or by public member of your Activity. For example my Solution:

  1. I created my surfaceview in RelativeLayout and add there textview also.

    <RelativeLayout ....>
        <com.package.my.MySurfaceView
                android:....... />
        <TextView
                android:id="@+id/textId
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
    </RelativeLayout>
    
  2. In MySurface:

    TextView tv=(TextView)MyActivity.MyAct.findViewById(R.id.textId);
    tv.offsetLeftAndRight(offsetX);
    tv.offsetTopAndBottom(offsetY);
    tv.setText("Your Text Here");
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜