как решить проблему с разрешением, если я создаю макет из кода?
Я проверил его на своем телефоне с разрешением 320 x 480, и он выглядит нормально. но когда я тестирую его в телефоне моих друзей (Galaxy S), похоже, что макет не растянулся.
Почему я создаю макет из кода, потому что я не знаю, как разместить кнопки в определенном месте.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rLayout = new RelativeLayout(this);//(RelativeLayout)findViewById(R.id.relativeLayout1);
rLayout.setBackgroundResource(R.drawable.menu_blankscreen);
InitializeLayout();
setContentView(rLayout);
}
private void InitializeLayout() {
ImageButton newGame = new ImageButton(this);
//newGame.setBackgroundResource(drawable.menu_button_new);
newGame.setBackgroundResource(R.drawable.menu_button_new_xml);
newGame.setOnClickListener(newGameClick);
addView(newGame, 5, 174, 149, 41);
ImageView continueGame = new ImageView(this);
continueGame.setBackgroundResource(R.drawable.menu_button_continue_xml);
continueGame.setOnClickListener(continueClick);
addView(continueGame, 5, 218, 149, 41);
ImageView highscore = new ImageView(this);
highscore.setBackgroundResource(R.drawable.menu_button_highscore_xml);
highscore.setOnClickListener(highscoreClick);
addView(highscore, 5, 262, 149, 41);
ImageView achievement = new ImageView(this);
achievement.setBackgroundResource(R.drawable.menu_button_achievement_xml);
achievement.setOnClickListener(achievementClick);
addView(achievement, 5, 306, 149, 41);
ImageView option = new ImageView(this);
option.setBackgroundResource(R.drawable.menu_button_option_xml);
option.setOnClickListener(optionClick);
addView(option, 5, 350, 149, 41);
ImageView quit = new ImageView(this);
quit.setBackgroundResource(R.drawable.menu_button_quit_xml);
quit.setOnClickListener(quitClick);
addView(quit, 5, 395, 149, 41);
Button btnTest = new Button(this);
btnTest.setText("Test");
btnTest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(StartMenuActivity.this, TestActivity.class);
startActivity(intent);
}
});
addView(btnTest, 270, 430,50, 50);
}
public void addView(View view, int x, int y, int width, int height) {
rParam = new RelativeLayout.LayoutParams(width, height);
rParam.leftMargin = x;
rParam.topMargin = y;
rLayout.addView(view, rParam);
}
Я предполагаю, что leftMargin - как x, а topMargin - как y.
это зависит от пикселей ??