Stan
Stan

Reputation: 63

Graphical layout is different when it's emulator

I see on my graphical layout what I want, center button on the top. On my emulator my button are on the top left corner.

My xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mairie01"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal" >
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/decourvrir1" />
<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/schedule" />
<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/decouvrir2" />
</LinearLayout>

Moreover : When I click on a button, impossible to use an other layout. Graphical layout is ok, but on my emulator no background for linearlayout and button.

Associated xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mairie01">
<Button
    android:id="@+id/manger"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/eat" />"
<Button
    android:id="@+id/dormir"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<Button
    android:id="@+id/autres"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
</LinearLayout>

Sorry for my poor english.

Upvotes: 0

Views: 655

Answers (2)

Stan
Stan

Reputation: 63

I fixed my problem with a simple clean of my project.

Upvotes: 1

Unavailable
Unavailable

Reputation: 681

Are you sure about that you're setting the correct layout content in your java code?

public class YourActivity extends Activity{

@Override
public void onCreate(Bundle savedInstanceState){


super.onCreate(savedInstanceState);
setContentView(R.layout.main);   // are you using your main.xml ?

// or programmatically created layout like the following:
//
// LinearLayout m_layout = new LinearLayout(this);
// for(int i=0; i<3; ++i){
// Button m_btn = new Button(this);
// m_layout.addView(m_btn);
// }
// 
// setContentView(this.m_layout);
//
// ...

}

// ...
// Your Activity Logic ...
// ...

}

if you didn't set layout orientation, LinearLayout's default orientation is HORIZONTAL. You can set it programmatically or by editing main.xml file like the following:

// ...
this.m_layout.setOrientation(LinearLayout.VERTICAL);
// ...

or

<LinearLayout android:id = "@+id/m_layout" android:orientation = "vertical" ...  />

Upvotes: 0

Related Questions