У меня есть 5 кнопок в Управлении с относительной компоновкой. У меня есть функция, называемая init(), которая будет перемещать кнопки с помощью setX() и setY(). Когда я вызываю init() изнутри onClickListener, кнопки перестраиваются без каких-либо проблем. Но когда я вызываю функцию от onCreate() или onStart(), журнал показывает, что функция выполнена, но кнопки остаются в том же положении. Что мне делать?Невозможно переместить представления программно в Activity android
Также, если я вызываю init() от onResume(), кнопки перемещаются без проблем.
public class MainActivity extends ActionBarActivity {
@Override
protected void onStart()
{
super.onStart();
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//if init() is called here I can see the Log "Tag/Init Executed" but the buttons are not repositioned
}
@Override
protected void onResume()
{
Log.i("Log", "resume called");
super.onResume();
//if i call init() here, the button is not repositioned but if i click home button and resume the app again, the button is repositioned.
}
public void init()
{
Log.i("Tag","Init Executed");
b1=(ImageButton)findViewById(R.id.imageButton);
b1.setX(p.x);
b1.setY(p.y);
}
}
обеспечивают некоторый код .... Я думаю, что ваши делать это перед зрением иерархии полностью inflatet –
я второй, что, но в 'OnStart()' зрения иерархия должна была завышена, немного кода поможет – trpride