开发者

Add TextView objects to SurfaceView

开发者 https://www.devze.com 2023-03-09 01:53 出处:网络
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 Activ

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

精彩评论

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