-1
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|left|center"
        android:gravity="right" >
        <ImageButton 
            android:id="@+id/Button1" 
            android:background="@null" 
            android:paddingLeft="5.0dip" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:src="@drawable/zoom_button1" 
            android:text="button1"
            android:visibility="gone" />

        <ImageButton
            android:id="@+id/Button2"
            android:layout_width="29dp"
            android:layout_height="wrap_content"
            android:background="@null"
            android:paddingLeft="5.0dip"
            android:src="@drawable/zoom_button2"
            android:text="button2" />
</LinearLayout>
    //MainActivity.java:
private ImageButton button1;
button1 = (ImageButton)findViewById(R.id.button1);
button1.setVisibility(View.GONE);

orientation="vertical"

I move the buttons on Eclipse activity_main.xml.

When I change button 1 and button2, the program will work on the place at first.

Should I change buttons in Eclipse or I should change them in the program?

Squonk
  • 48,735
  • 19
  • 103
  • 135
Chunhao
  • 91
  • 1
  • 8

1 Answers1

0

An xml file is to specify the layout properties, you can also write in Java an entire layout, adding all of the elements you need by code. You will still need an xml file though.
Depending on what you change, the buttons can be moved around the screen and scaled/colored etc without affecting functionality.

Here is a good post about performance of Java vs xml code.

Generally UI elements need to be in Java if yuo want them to be dynamic (do stuff at runtime) but if they re just passive (other than buttons and simple interactive elements you find in the widgets section) then xml is a great way to format and see where everything is. In other words, it's easy to visualise what it will look like and where problems might occur in xml, but the Java is more powerful.

Community
  • 1
  • 1