【问题标题】:Can we embed button inside the min3d screen?我们可以在 min3d 屏幕中嵌入按钮吗?
【发布时间】:2013-07-29 04:19:15
【问题描述】:

是否可以在使用 android 中的 Min3d 框架完成的工作 3d 动画的底部插入一个按钮。我确实有一辆正在旋转的 3d 模型车。我想在这个工作动画屏幕的底部放一个按钮。是否有可能,因为我没有使用任何布局。请举例说明,以便我可以在我的程序中复制相同的内容。

【问题讨论】:

    标签: android min3d


    【解决方案1】:

    是的。相反,该过程是使用 glSurfaceView 将 min3d 框架添加到布局中。以下代码重点介绍了如何实现相同的目标,假设您已经涵盖了其他基础知识(例如加载对象)。如果没有,则在本简报末尾提供相同的链接。

        //import statements
        public class threedviewActivity extends RendererActivity implements View.OnClickListener,View.OnTouchListener{ 
        //onClick and onTouch in case you want to recognize both touch and click on the button
    
             //initialize the variables you require
    
             @Override
             public void onCreateSetContentView() {
    
                  setContentView(R.layout.activity_example);
                  RelativeLayout R1 = (RelativeLayout)this.findViewById(R.id.SceneHolder);
                  R1.addView(_glSurfaceView); //adding the min3d view into the layout
    
                  Button example_1 = (Button)this.findViewById(R.id.example_1);
                  Button example_2 = (Button)this.findViewById(R.id.example_2);
    
                  example_1.setOnTouchListener(this);
                  example_2.setOnClickListener(this);
    
             }
    
             public boolean onTouch(View $v, MotionEvent event) {
    
                  switch($v.getId())
                  {
                       case R.id.example_1:
                            //Your actions and things to do
                       case R.id.example_2:
                            //your code
    
                  }
    
             }
    
             public void onClick(View $v)
             {
                  //similar to above      
             }
    
             public void initScene()
             {
                  //initialize object and other activities related to the 3d container
    
             }
    
             @Override
             public void updateScene()
             {
    
                  //update effects such as rotation on the object here, based on the button click or touch, etc.
    
             }
    
        }
    

    包含布局/活动的 xml 文件应如下所示:

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    
         <Button
             //your data
             android:id="@+id/example_1"
         />
    
         <Button
             //your data
             android:id="@+id/example_2"
         />
    
         <RelativeLayout
             //nested layout which will hold the 3d container
             android:id="@+id/SceneHolder">
    
         </RelativeLayout>
    
      </RelativeLayout>
    

    要了解更多关于initScene() 函数的工作,您可以参考herehere

    您还可以通过调整照明属性来添加额外的效果,如 here 所述

    添加到布局的基本示例取自here。同一页面还提供了许多示例的链接,以备您将来使用。

    【讨论】:

      猜你喜欢
      • 2019-03-11
      • 2021-10-06
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多