我有一个线性布局。我正在运行时添加项目。但所有项目都是从顶部到底部显示的。现在我正在尝试从 BOTTOM 到 TOP 显示项目。
我是说。我想从 BOTTOM 到 TOP 以线性布局设置项目。
这是我的线性布局:-
messagesContainer = (ViewGroup) findViewById(R.id.messagesContainer);
scrollContainer = (ScrollView) findViewById(R.id.scrollContainer);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
if (!leftSide) {
bgRes = R.drawable.right_message_bg;
params.gravity = Gravity.RIGHT;
params.leftMargin=30;
}
else
{
params.gravity = Gravity.LEFT;
params.rightMargin=30;
}
textView.setLayoutParams(params);
textView.setBackgroundResource(bgRes);
runOnUiThread(new Runnable() {
@Override
public void run() {
messagesContainer.addView(textView,messagesContainer.getChildCount());
//messagesContainer.bringChildToFront(textView);
// Scroll to bottom
if (scrollContainer.getChildAt(0) != null) {
scrollContainer.scrollTo(scrollContainer.getScrollX(), scrollContainer.getChildAt(0).getHeight());
}
scrollContainer.fullScroll(View.FOCUS_DOWN);
scrollContainer.pageScroll(View.FOCUS_DOWN);
}
});
请帮我。