将 xml 文件包装在relativelayout中 setContentView(R.layout.activity_main); -->新的相对布局(这个);
我想将activity_xml 包装在RelativeLayout 中,我尝试了几种方法,但没有起作用。是否可以? 我的叫做 gameButtons --> gameButtons.addView(#问题如何在此处添加activity_xml#);
public class Game extends AppCompatActivity {
GamePanel gameView; // The class extending SurfaceView
FrameLayout game; // Holder between SurfaceView and RelativeLayout
RelativeLayout gameButtons; // Where I add the buttons
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Creating Layout Objects
gameView = new GamePanel(this);
game = new FrameLayout(this);
gameButtons = new RelativeLayout(this);
ContentView activityView = ContentView(R.layout.activity_main);
RelativeLayout.LayoutParams activityMain = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
//Define the layout parameter for whatever we want to wrap both width and heigth
RelativeLayout.LayoutParams parameters = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);
// Matching with the content we want to add
gameButtons.setLayoutParams(parameters);
gameButtons.addView(activityView); << ---- PROBLEM !!
//setContentView(R.layout.activity_main);
setContentView(new GamePanel(this));
}
}
我希望能够通过相对布局显示来自 Activity_main 的按钮和其他内容。
我需要使用按钮的意图函数 = Activity_xml 中的按钮
我尝试了这些gameButtons.addView(activity_xml);
*gameButtons.addView(ContentView(R.layout.activity_main));
*gameButtons.addView(R.layout.activity_main);
*gameButtons.addView(activityView);
*// 我玩ContentView的地方activityView = ContentView(R.layout.activity_main);
I want to wrap activity_xml in a RelativeLayout, I tried several ways, bit non is working. Is it possible?
Mine is called gameButtons --> gameButtons.addView(#problem how to add activity_xml here#);
public class Game extends AppCompatActivity {
GamePanel gameView; // The class extending SurfaceView
FrameLayout game; // Holder between SurfaceView and RelativeLayout
RelativeLayout gameButtons; // Where I add the buttons
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Creating Layout Objects
gameView = new GamePanel(this);
game = new FrameLayout(this);
gameButtons = new RelativeLayout(this);
ContentView activityView = ContentView(R.layout.activity_main);
RelativeLayout.LayoutParams activityMain = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
//Define the layout parameter for whatever we want to wrap both width and heigth
RelativeLayout.LayoutParams parameters = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);
// Matching with the content we want to add
gameButtons.setLayoutParams(parameters);
gameButtons.addView(activityView); << ---- PROBLEM !!
//setContentView(R.layout.activity_main);
setContentView(new GamePanel(this));
}
}
I expected the posibility to both show buttons from activity_main and other content under via the RelativeLayout..
I need to use the intent functions for buttons = the buttons in activity_xml
I tried thesegameButtons.addView(activity_xml);
*gameButtons.addView(ContentView(R.layout.activity_main));
*gameButtons.addView(R.layout.activity_main);
*gameButtons.addView(activityView);
*// where I played with ContentView activityView = ContentView(R.layout.activity_main);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以新手编码器找到了解决方案! = 那就是我!
就我而言,
我将其添加到
现在它可以工作了!
So the newbie coder found the solution!! = That is me!
in my case
I added that in
And now it works!