多重活动单布局 [英] Multiple Activities Single Layout

查看:78
本文介绍了多重活动单布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多的活动,做同样的事情的整体。是否有可能让它们使用相同的布局?我试着用code以下,但布局将被转移的方式离开的地步,按钮会关闭屏幕。

 的setContentView(R.layout.activity_enter_pin);

TextView的SecondEP =(TextView中)findViewById(R.id.EnterPin);
SecondEP.setText(请输入新的PIN码);
 

解决方案

不应该有与任何问题,但如果您使用的是相同的布局做同样的事情在不同的活动情况下,你可能要考虑设置你的装饰物为片段所以它可以在两个重复使用活动秒。

请参见 Android的碎片开发者指南了解更多信息。

I have many activities that do the same thing overall. Is it possible to have them use the same layout? I tried using the code below, but the layout would be shifted way to left to the point where buttons would be off the screen.

setContentView(R.layout.activity_enter_pin);

TextView SecondEP = (TextView) findViewById(R.id.EnterPin);
SecondEP.setText("Enter NEW Pin");

解决方案

There shouldn't be any problem with that, but if you are using the same layout to do the same thing in different Activity instances, you may want to look into setting up your doodad as a Fragment so it can be reused in both Activitys.

See the Android Fragments Developer Guide for more information.

这篇关于多重活动单布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆