gpt4 book ai didi

android - 以编程方式将 SurfaceView 添加到在 ImageView 下按 Z 顺序排列的 FrameLayout

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:30:05 25 4
gpt4 key购买 nike

EDIT 2a:对于简洁的问题,请随意跳到底部。

我可以Draw a SurfaceView via xml .就我而言,我正在创建一本电子书,该书的每一页都会在 SurfaceView 上运行不同的动画。

我有一个 .xml 布局,它有一个名为 @+id/animation_layoutFrameLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<fi.harism.curl.CurlView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/curl"
>
</fi.harism.curl.CurlView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/animation_layout"
/>
<include layout="@layout/narration"
/>
</RelativeLayout>

根据正在显示的书的哪一页,我想在我的扩展 SurfaceView 的类集中添加其中一个类的不同实例。

Page01SurfaceView extends PageAniSurfaceView {
//
// code here includes onDraw() definition
//
}

Page02SurfaceView extends PageAniSurfaceView {
//
// code here includes onDraw() definition
//
}

PageAniSurfaceView 基本上在实例化时创建一个线程,并在创建其 View 时启动该线程。

public class PageAniSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private final String TAG = this.getClass().getSimpleName();
private TutorialThread _thread;

public PageAniSurfaceView(Context context) {
super(context);
init();
}

public PageAniSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public void setBackground(int bg_id)
{
// adding the callback (this) to the surface holder to intercept events
getHolder().addCallback(this);
// make the PageAniSurfaceView focusable so it can handle events
setFocusable(true);

}

protected void init()
{
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
_thread = new TutorialThread(getHolder(), this);
_thread.setRunning(true);
_thread.start();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
_thread.setRunning(false);
while (retry) {
try {
_thread.join();
retry = false;
} catch (InterruptedException e) {
// we will try it again and again...
}
}
}

protected void draw_bitmaps(Canvas canvas)
{
// will be overridden by child classes
}

@Override
protected void onDraw(Canvas canvas) {
if(this.getVisibility() == View.VISIBLE)
{
if(canvas != null)
{
draw_bitmaps(canvas);
}
}
}

public void update_bitmaps()
{
// will be overridden by child classes
}

public void elementStarted(PageElement _pageElement) {
// Nothing in parent class
}

public void elementFinished(PageElement mElement) {
// Nothing in parent class
}
}

我有一个名为 PageDisplayer 的类,它跟踪我们所在的页面,并且 addView() 应该是我需要为该页面包含的特定 SurfaceView 类.

public void displayPage()
{
page = sSystemRegistry.pageSystem.getCurrentPage();
mBookReader.mAnimationLayout.removeAllViews();

PageAniSurfaceView _ani = null;

switch(page.index)
{
case 1:
_ani = new Page01SurfaceView(mBookReader);
break;
case 2:
_ani = new Page02SurfaceView(mBookReader);
break;
case 3:
_ani = new Page03SurfaceView(mBookReader);
break;

}

if(_ani != null)
{
_ani.setWillNotDraw(false);
// mBookReader.mAnimationLayout is a FrameLayout in my .xml
mBookReader.mAnimationLayout.addView(_ani);
mElementDisplayer.setElementListener(_ani);
}
}

通过断点或 LogCat,我可以知道线程正在运行,并且正在调用 onDraws。在例如 Page01SurfaceView 中定义和显示的位图被绘制一次,但当 update_bitmaps() 更改位图的 (x,y) 坐标时不会重新绘制。

为什么每次调用 onDraw(Canvas) 时都没有绘制位图?

编辑:如果位图上方的 View 中有动画,则显示 SurfaceView 上的位图。

编辑 2:简洁的问题:

SurfaceView 上方按 Z 顺序排列的 ImageView 是否会阻止 SurfaceView 自行绘制?

我应该只使用 View 吗?而不是 SurfaceView?我会尝试一下并报告。

最佳答案

我只是在使用 View,而不是 SurfaceView。

Dianne Hackborn 说“表面 View 非常特殊并且不是真正的 View (表面是一个单独的窗口 Z-ordered with your own),它们的 Z-ordering 与您的 View 不匹配。表面 View 是一个大而重的对象;您不打算以这种方式将 SurfaceView 视为常规 View 。”

https://groups.google.com/d/topic/android-developers/COffLpanlz0/discussion

关于android - 以编程方式将 SurfaceView 添加到在 ImageView 下按 Z 顺序排列的 FrameLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6578578/

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