Thursday, March 27, 2014

android setText () position changed after the component


Younger beginner android one week ......
Question:
I absolutely layout.
There are two buttons in the interface, because it is absolutely the layout so I put two buttons placed in the middle of the screen, do not overlap.
I activity in the first seconds of the button1 position change it, use the button.layout (int l, int t, int r, int b)
Button2 refresh the contents of the next second, the use is button.setText ("");

I found that after the second seconds to refresh the contents of button2, button1 I will go to the initial position layout ......
I would like to ask how not to let go button1 original position. In the second sec button1 I have not changed the layout ......
Thank you for the

 
package m.m.m;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;

public class test extends Activity {
/ ** Called when the activity is first created. * /
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);

Message msg = mHandler.obtainMessage ();
msg.what = 1001;
mHandler.sendMessageDelayed (msg, 1000);
}

int k = 0;

Handler mHandler = new Handler () {
public void handleMessage (Message msg) {
switch (msg.what) {
case 1001:
/ *
* Here is the location of button1 changes
** /
Button bt1 = (Button) findViewById (R.id.button1);
bt1.layout (20, 20, 50, 50);

Message mg1 = mHandler.obtainMessage ();
mg1.what = 1002;
mHandler.sendMessageDelayed (mg1, 1000);
break;
case 1002:
/ *
* Here are the contents are changed
button2** /
Button bt2 = (Button) findViewById (R.id.button2);
bt2.setText ("" + k);
k + +;

Message mg2 = mHandler.obtainMessage ();
mg2.what = 1001;
mHandler.sendMessageDelayed (mg2, 1000);
break;
}
super.handleMessage (msg);
}
};
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Brother have been waiting for answers
Reply:
The layout of the document, and then figure it
Reply:
By thread
Reply:
Students did not see what the problem is, ah, the layout of the document is also posted come.
Reply:
Thank you Replies:
The following are the main documents

My question is, button1 original in position 1, in the first second I modified its position changed to position 2, in the second second time I did not change its position, just modify the button2's text, however, they themselves went button1 Position 1, which is what to ask, how to avoid? ? ?
Grateful

  
android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: id = "@ + id / ly"
>
< br /> < br />


Reply:
In fact, I use the absolute layout, but the layout of a single needle into the above does not work, the teacher had said to change a single pin, can, I tried not ......
The following is the main
my absolute layout
  
android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: id = "@ + id / ly"
>
< br /> < br />


Reply:
Layout files changed a bit:

android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: background = "# ffffff"
android: orientation = "vertical">

android: layout_height = "100px"
android: orientation = "vertical">

No comments:

Post a Comment