Thursday, February 20, 2014

How android program automatically adapt to the screen size


xml:

xmlns: android = "http://schemas.android.com/apk/res/android"
xmlns: tools = "http://schemas.android.com/tools"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: rowCount = "10"
android: columnCount = "4"
android: id = "@ + id / mainwindow"

>

android: id = "@ + id / show"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: scrollbars = "vertical"
android: singleLine = "false"
android: textSize = "50sp"
android: layout_gravity = "right"
android: background = "# 000"
android: textColor = "@ color / red"
android: gravity = "right"
/>


java:
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.calculator);

tableLayout = (TableLayout) findViewById (R.id.mainwindow);
text = (TextView) findViewById (R.id.show);
text.setMovementMethod (ScrollingMovementMethod.getInstance ());
text.setLines (2);
Button [] bn = new Button [20];

tableLayout.setStretchAllColumns (true);
tableLayout.setShrinkAllColumns (true);

int n = 0;
for (int i = 0; i <5; i + +) {
TableRow textrow = new TableRow (this);
for (int j = 0; j <4; j + +) {
bn [n] = new Button (this);
bn [n] setText (chars [n]);.
. bn [n] setTextSize (30);
TableRow.LayoutParams lp = new TableRow.LayoutParams (
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
textrow.addView (bn [n], lp);
n + +;
}
tableLayout.addView (textrow);
}
}

How to make android under the program automatically adapt to various screen sizes, this program on a virtual machine can automatically adapt to the screen size, but one can not be installed to the phone automatically adapt the above screen size<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
 TableRow.LayoutParams lp = new TableRow.LayoutParams (
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

Sentence changed to:
 TableRow.LayoutParams lp = new TableRow.LayoutParams (
0, LayoutParams.WRAP_CONTENT, 1);

Try landlord
Reply:
Pictured in effect a standard, each to calculate the size of the various components, such as width = width * (renderings width / actual screen width)
Is the same height
Reply:
reference to the second floor lieri111 reply:
to the effect of a standard, each to calculate the size of the various components, such as width = width * (renderings width / The actual screen width)
Height is the same

Will the next renderings width What does this mean? I use the button
Reply:
cited a floor ncepu307 reply:
 TableRow.LayoutParams lp = new TableRow.LayoutParams (
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

Sentence changed to:
 TableRow.LayoutParams lp = new TableRow.LayoutParams (
0, LayoutParams.WRAP_CONTENT, 1);

Landlord try

Tried, the same effect it

No comments:

Post a Comment