Answer the question
In order to leave comments, you need to log in
Apk android is crooked, the display of elements is incorrect, how to fix it?
Started learning android in android studio.
With the help of the editor, I brought out a couple of buttons and a text field, added a button handler, etc.
Collected the project, uploaded to the phone. But the display is not correct. All items are in the top right corner.
The code:
public class MainActivity extends AppCompatActivity {
private TextView text = null;
private Button OK = null;
private Button cancel = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
setContentView(R.layout.my_screen);
text = (TextView) findViewById(R.id.textView);
OK = (Button) findViewById(R.id.button);
cancel = (Button) findViewById(R.id.button2);
OK.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
text.setText("You pressed OK button!");
OK.setEnabled(false);
cancel.setEnabled(true);
}
});
cancel.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
text.setText("You pressed Cancel button!");
OK.setEnabled(true);
cancel.setEnabled(false);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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">
<TextView
android:id="@+id/textView"
android:layout_width="179dp"
android:layout_height="42dp"
android:text="Hello this world"
tools:layout_editor_absoluteX="34dp"
tools:layout_editor_absoluteY="16dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
tools:layout_editor_absoluteX="34dp"
tools:layout_editor_absoluteY="75dp" />
<Button
android:id="@+id/button2"
android:layout_width="118dp"
android:layout_height="46dp"
android:text="Cancel"
tools:layout_editor_absoluteX="34dp"
tools:layout_editor_absoluteY="149dp" />
</android.support.constraint.ConstraintLayout>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question