android 多个activity使用过同一个view,android - 有没有一种方法可以在一个Activity中同时使用多个Libgdx View? - 堆栈内存溢出...

我试图在单个Activity中添加两个AndroidFragmentApplication。 但是只有最后添加的片段实际上在屏幕上呈现。 其他片段未显示任何内容。 我需要怎么做才能绘制两个视图?

我首先尝试使用AndroidApplication类初始化视图。 但这导致应用崩溃。 然后,我添加了多个片段来扩展AndroidFragmentApplication。 现在,该应用程序不会崩溃,只有最后添加的片段会在屏幕上绘制。

这是我添加片段的地方

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="#ffffff">

android:layout_width="80dp"

android:layout_height="100dp"

android:layout_gravity="center"

android:id="@+id/alpha_fragment"

android:name="com.sample.libgdx_final.AlphaFragment" />

android:id="@+id/coin_fragment"

android:layout_width="100dp"

android:layout_height="100dp"

android:name="com.sample.libgdx_final.CoinFragment"

/>

这是我的Fragment和ApplicationListener-

public class CoinFragment extends AndroidFragmentApplication implements AndroidFragmentApplication.Callbacks{

@Nullable

@Override

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

return initializeForView(new CoinTranslateLibgdx());

}

}

CoinTranslateLibgdx.java

class CoinTranslateLibgdx extends ApplicationAdapter {

private SpriteBatch batch;

private Texture texture;

private Sprite sprite;

private float deltaTime = 0f;

private boolean increasing = true;

@Override

public void create() {

batch = new SpriteBatch();

texture = new Texture(Gdx.files.internal("token.png"));

sprite = new Sprite(texture);

sprite.setCenterX(Gdx.graphics.getWidth() / 2f);

sprite.setCenterY(Gdx.graphics.getHeight());

}

@Override

public void render() {

Gdx.gl20.glClearColor(0, 0, 0, 0);

batch.begin();

if (deltaTime <= 1 && increasing) {

deltaTime += Gdx.graphics.getDeltaTime() * 1f;

} else if (deltaTime >= 0.09) {

increasing = false;

deltaTime -= Gdx.graphics.getDeltaTime() * 1f;

} else {

increasing = true;

}

batch.setColor(1, 1, 1, deltaTime);

batch.draw(sprite, 0, 0);

batch.end();

}

@Override

public void dispose() {

batch.dispose();

texture.dispose();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值