我在图形布局上看到了我想要的东西,顶部是中心按钮。 在我的模拟器上,我的按钮位于左上角。
我的xml文件:
<?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>
此外: 当我点击按钮时,无法使用其他布局。 图形布局没问题,但在我的模拟器上没有线性布局和按钮的背景。
关联的xml文件:
<?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>
抱歉我的英语很差。
答案 0 :(得分:1)
我通过简单清理我的项目解决了我的问题。
答案 1 :(得分:0)
您确定在java代码中设置了正确的布局内容吗?
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 ...
// ...
}
如果未设置布局方向,则LinearLayout的默认方向为HORIZONTAL。您可以通过编程方式或通过编辑main.xml文件来设置它,如下所示:
// ...
this.m_layout.setOrientation(LinearLayout.VERTICAL);
// ...
或
<LinearLayout android:id = "@+id/m_layout" android:orientation = "vertical" ... />