gpt4 book ai didi

android - Fragment 中的 TextureView 从不调用 onSurfaceTextureAvailable

转载 作者:行者123 更新时间:2023-11-29 18:02:17 62 4
gpt4 key购买 nike

我已经看到很多在主 Activity 中使用 TextureView 的示例,但我正在尝试将其放入 Fragment 中。

我已经创建了最简单的示例,它的 onCreateView 被调用,onActivityCreated 也被调用,但是 onSurfaceTextureAvailable 在传回 TextureView 后没有被调用。

我错过了什么?

谢谢G

public class FullscreenActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
}
}

public class TextureViewFragment extends Fragment
implements TextureView.SurfaceTextureListener {

private TextureView mTextureView;

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

mTextureView = new TextureView(getActivity());
mTextureView.setSurfaceTextureListener(this);
mTextureView.setOpaque(false);
return mTextureView;
}

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
}

@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
// TODO Auto-generated method stub
return false;
}

@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width,
int height) {
// TODO Auto-generated method stub
}

@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
// TODO Auto-generated method stub
}
}


activity_fullscreen.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".FullscreenActivity" >

<fragment class="com.example.test.TextureViewFragment"
android:id="@+id/graphTextureView"
android:layout_width="0px" android:layout_height="match_parent" />
</FrameLayout>

最佳答案

这是因为 TextureView 必须具有非零大小并且可见。根据评论,layout_width 设置为 0px。将其更改为非零值。

(老问题,但为后代发布答案)

关于android - Fragment 中的 TextureView 从不调用 onSurfaceTextureAvailable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15320175/

62 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com