滚动动态创建的ScrollView以结束Java android
如果我有这个空白,它将多个RelativeLayout添加到单个RelativeLayout(messages\u container\u view)中,然后将其添加到滚动视图(MessagesScrollingView)中,我可以看到消息,但滚动视图默认为顶部。我希望它默认为滚动视图的底部 滚动视图是动态创建的 我可以看到滚动视图和消息滚动动态创建的ScrollView以结束Java android,java,android-layout,Java,Android Layout,如果我有这个空白,它将多个RelativeLayout添加到单个RelativeLayout(messages\u container\u view)中,然后将其添加到滚动视图(MessagesScrollingView)中,我可以看到消息,但滚动视图默认为顶部。我希望它默认为滚动视图的底部 滚动视图是动态创建的 我可以看到滚动视图和消息 public void individualConversationMessages(final Context ctx){ runOnUiThrea
public void individualConversationMessages(final Context ctx){
runOnUiThread(new Runnable() {
@Override
public void run() {
//Clear the screen
MB.removeAllViews();
//Set up the screen dimensions
Display display = getWindowManager().getDefaultDisplay();
//This is where the individual conversation will get stored
JSONArray ConversationMessages = new JSONArray();
int container_id = 1;
//The messages go in this container which goes in the scrollbox
RelativeLayout messages_container_view = new RelativeLayout(ctx);
try {
//Get all conversations on the device
JSONArray Conversations = new JSONArray(SharedPrefs(ctx).getString("conversations_array", ""));
//Store only a single conversation
ConversationMessages = Conversations.getJSONArray(ConversationID);
//This is how many messages are in the conversation.
int MessageCount = ConversationMessages.length();
for(int i = 0;i<MessageCount;i++){
//Get the message we are displaying
JSONObject MessageData = ConversationMessages.getJSONObject(i);
//Message container
RelativeLayout MessageContainer = new RelativeLayout(ctx);
//Set all the messages in the conversation to read so that they no longer appear.
MessageData.put("read",1);
//This is where the message will be displayed
MessageContainer.setMinimumWidth(display.getWidth());
//This is the message information we will be displaying.
TextView message_text = new TextView(ctx);
//Set the message data
String body = "\n" + MessageData.getString("sent") + "\n" + MessageData.getString("message");
message_text.setText(body);
//Make those a nice easy to read size
message_text.setTextSize(13);
//Add the message text and sent time to the container
MessageContainer.addView(message_text);
MessageContainer.setMinimumHeight(message_text.getMeasuredHeight() + 20);
//Layout params
if(container_id != 0) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, container_id);
MessageContainer.setLayoutParams(params);
}
container_id++;
MessageContainer.setId(container_id);
//Add the message container to the view of messages
messages_container_view.addView(MessageContainer);
//Save all the messages in this conversation to red status
SharedPrefs(ctx).edit().putString("conversations_array", Conversations.toString()).commit();
}
} catch (Exception e){
TextView message = new TextView(ctx);
message.setTextSize(15);
message.setTextColor(Color.parseColor("#ff0000"));
message.setText("Error \n \n Something went wrong \n \n" + e.getClass().getSimpleName());
MB.addView(message);
e.printStackTrace();
}
//Add the messages into the scrolling view.
ScrollView MessagesScrollingView = new ScrollView(MyMessages.this);
MessagesScrollingView.addView(messages_container_view);
MessagesScrollingView.scrollTo(0, MessagesScrollingView.getBottom());
MB.addView(MessagesScrollingView);
}
});
}
public void individualConversationMessages(最终上下文ctx){
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
//清除屏幕
MB.removeAllViews();
//设置屏幕尺寸
Display Display=getWindowManager().getDefaultDisplay();
//这是存储个人对话的地方
JSONArray ConversationMessages=新的JSONArray();
int container_id=1;
//消息进入这个容器,这个容器进入滚动框
RelativeLayout消息\容器\视图=新的RelativeLayout(ctx);
试一试{
//获取设备上的所有对话
JSONArray Conversations=新的JSONArray(SharedPrefs(ctx).getString(“Conversations_array”,”);
//只存储一次对话
ConversationMessages=Conversations.getJSONArray(ConversationID);
//这是对话中有多少条消息。
int MessageCount=ConversationMessages.length();
对于(int i=0;i