Ask a question I want to use a custom GameView main.xml layout file, there have been unexpected stop condition
If the layout setContentView (R.layout.main); instead setContentView (gameView); no problem, but I also need to display a page other content
TestdActivity.java
public class TestdActivity extends Activity {
GameView gameView = null;
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
gameView = new GameView (this);
setContentView (R.layout.main);
/ / SetContentView (gameView);
}
}
main.xml
android: layout_height = "fill_parent"
android: orientation = "vertical">
android: layout_height = "wrap_content"
/>
GameView.java
public class GameView extends View {
public GameView (Context context) {
super (context);
}
protected void onDraw (Canvas canvas) {
super.onDraw (canvas);
}
}
My GameView inside nothing to write, I do not know whether the layout file main.xml wrong, can yield components such as the GameView used
Because I need to show other groups such as button in a window, etc., which show how
Reply:
Online, help
Reply:
Friendly Bangding
Reply:
Reply:
Reply:
I also want to know only Bangding
Reply:
public GameView (Context context) {
super (context);
}
When the components used, the constructor parameters changed to two.
Reply:
Are you saying that there are two constructors? Another parameter of a constructor is? Novice
Reply:
LayoutInflater inflater = LayoutInflater.from (this);
/ / Or
/ / LayoutInflater inflater = getLayoutInflater ();
View layout1 = inflater.inflate (R.layout.test, null);
Button bt1 = (Button) layout1.findViewById (R.id.clickMeBtn);
Xml file is to obtain two components do
Reply:
LZ did not understand what to say
Reply:
There should be a problem constructor needs to be rewritten
public GameView (Context context, AttributeSet attributeSet)
{
supe (context, attributeSet);
}
Reply:
Above this man say is that I'm free to go try, thank you
Reply:
Rewrite View constructor with two parameters on the line.
Reply:
Reply:
To configure a custom View controls to xml file must be replicated supe (context, attributeSet) constructor, which is AttributeSet attributeSet parameter must have, otherwise configured to xml can not run,
public GameView (Context context, AttributeSet attributeSet)
{
supe (context, attributeSet);
}
No comments:
Post a Comment