android gvr 流媒体,How to change position of Toast in Android?

You can customize the location of your Toast by using:

setGravity(int gravity, int xOffset, int yOffset)

This allows you to be very specific about where you want the location of your Toast to be.

One of the most useful things about the xOffset and yOffset parameters is that you can use them to place the Toast relative to a certain View.

For example, if you want to make a custom Toast that appears on top of a Button, you could create a function like this:

// v is the Button view that you want the Toast to appear above

// and messageId is the id of your string resource for the message

private void displayToastAboveButton(View v, int messageId)

{

int xOffset = 0;

int yOffset = 0;

Rect gvr = new Rect();

View parent = (View) v.getParent();

int parentHeight = parent.getHeight();

if (v.getGlobalVisibleRect(gvr))

{

View root = v.getRootView();

int halfWidth = root.getRight() / 2;

int halfHeight = root.getBottom() / 2;

int parentCenterX = ((gvr.right - gvr.left) / 2) + gvr.left;

int parentCenterY = ((gvr.bottom - gvr.top) / 2) + gvr.top;

if (parentCenterY <= halfHeight)

{

yOffset = -(halfHeight - parentCenterY) - parentHeight;

}

else

{

yOffset = (parentCenterY - halfHeight) - parentHeight;

}

if (parentCenterX < halfWidth)

{

xOffset = -(halfWidth - parentCenterX);

}

if (parentCenterX >= halfWidth)

{

xOffset = parentCenterX - halfWidth;

}

}

Toast toast = Toast.makeText(getActivity(), messageId, Toast.LENGTH_SHORT);

toast.setGravity(Gravity.CENTER, xOffset, yOffset);

toast.show();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Google VR SDK来展示360度全景图。首先,你需要将全景图作为纹理加载到OpenGL ES中,并将其用作天空盒子的背景。然后,你可以创建一个Sphere(球体)或者Cube Map(立方体映射)来渲染全景图。接下来,你可以使用Google VR SDK提供的GvrView组件来创建一个VR场景,并将渲染的全景图作为场景的背景。最后,你可以使用GvrView组件提供的控制器来让用户在VR场景中移动和交互。 以下是一个简单的示例代码: ``` public class MainActivity extends AppCompatActivity { private GvrView gvrView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gvrView = findViewById(R.id.gvr_view); gvrView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); gvrView.setRenderer(new MyRenderer(this)); gvrView.setTransitionViewEnabled(false); // Enable VR Mode. gvrView.setStereoModeEnabled(true); gvrView.setDistortionCorrectionEnabled(true); // Enable Cardboard-trigger feedback. gvrView.enableCardboardTriggerEmulation(); // Associate the GvrView with this activity. gvrView.setTransitionViewEnabled(false); gvrView.setOnCloseButtonListener(new Runnable() { @Override public void run() { finish(); } }); } @Override protected void onResume() { super.onResume(); gvrView.onResume(); } @Override protected void onPause() { super.onPause(); gvrView.onPause(); } @Override protected void onDestroy() { gvrView.shutdown(); super.onDestroy(); } } ``` 你同样需要实现一个MyRenderer类,它继承自GvrView.Renderer,并在onDrawFrame()方法中渲染全景图。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值