Представьте себе эту иерархию:
Дело 1
RelativeLayout (screen size)
|
-> RelativeLayout (centered)
| |->TextView
|
|
-> buttonLayout (below the former RelativeLayout)
|->Button
С этим я получаю ожидаемый результат, текстовое представление в середине экрана и чуть ниже кнопки.
Но если я добавлю свиток:
Case 2
ScrollView
|
-> RelativeLayout (screen size)
|
-> RelativeLayout (centered)
| |->TextView
|
|
-> buttonLayout (below the former RelativeLayout)
|->Button
Тогда все выглядит одинаково, но кнопка игнорирует «правило ниже» и отображается почти в верхней части экрана. Я просто не могу понять почему. Любая помощь?
Спасибо за помощь.
Грег
код:
// Готов к делу 2
public View createOwnLayout()
{
ScrollView scrollView = new ScrollView(this);//Comment for case 1
RelativeLayout parentView = new RelativeLayout(this);
parentView.setBackgroundColor(0xff990000);
//--------------------------------- LINEAR LLAYOUT ---------------------------------//
LinearLayout centerLL = new LinearLayout(this);
centerLL.setId(CommonOpsAndValues.CONNECTION_ACTIVITY_IMAGE_LINEAR_LAYOUT);
centerLL.setOrientation(LinearLayout.VERTICAL);
centerLL.setBackgroundResource(R.drawable.rainbow);
centerLL.setBackgroundColor(0xff555599);
RelativeLayout.LayoutParams centerLLLP = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
centerLLLP.addRule(RelativeLayout.CENTER_HORIZONTAL);
centerLLLP.addRule(RelativeLayout.CENTER_IN_PARENT);
parentView.addView(centerLL,centerLLLP);
TextView serverLabel = new TextView(this);
serverLabel.setText("HELLO");
serverLabel.setTextColor(0xffffffff);
serverLabel.setTextSize(LABEL_TEXT_SIZE);
serverLabel.setPadding(INPUT_TEXTBOX_TEXT_PADDING, 0,0,0);
LinearLayout.LayoutParams serverLabelLLP = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
serverLabelLLP.gravity = Gravity.LEFT;
centerLL.addView(serverLabel,serverLabelLLP);
//---------------------------- LINEAR LLAYOUT ---------------------------/
//---------------------------- BUTTON LAYOUT---------------------------/
LinearLayout buttonLayout = new LinearLayout(this);
buttonLayout.setGravity(Gravity.CENTER);
buttonLayout.setBackgroundColor(0x00000000);
Button button = new Button(this);
button.setText("DO");
button.setClickable(true);
LinearLayout.LayoutParams buttonLP = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
buttonLayout.addView(button,buttonLP );
//---------------------------- BUTTON LAYOUT ---------------------------/
RelativeLayout.LayoutParams buttonLayoutLP = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
buttonLayoutLP.addRule(RelativeLayout.CENTER_HORIZONTAL);
buttonLayoutLP.addRule(RelativeLayout.BELOW,centerLL.getId());
parentView.addView(buttonLayout,buttonLayoutLP);
scrollView.addView(parentView,new FrameLayout.LayoutParams(AppManager.g_ScreenWidth,AppManager.g_ScreenHeight));//Comment for case 1
scrollView.setFillViewport(false);//Comment for case 1
//return parentView; //Uncomment for case 1
return scrollView;//Comment for case 1
}