我在图形布局上看到我想要的,顶部的中心按钮。 在我的模拟器上,我的按钮位于左上角。当它是模拟器时,图形布局是不同的
我的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>
此外: 当我点击一个按钮,不可能使用其它的布局。 图形布局是好的,但在我的模拟器上没有linearlayout和button的背景。
相关联的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>
对不起,我英文不好。
是的,我设置了正确的布局。我的xml文件是main.xml \ n [code] public class main extends活动{0}当第一次创建活动时调用。 */ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main);我会尝试以编程方式,但如何访问按钮(以setText为例)在我的循环后? – Stan
对于我的主要活动,可以这样做: LinearLayout m_layout = new LinearLayout(this); \t \t \t \t \t \t \t m_layout.addView(viePratique); \t \t \t \t \t \t \t m_layout.addView(decouvrir); \t \t \t \t \t \t \t m_layout.addView(agenda); \t \t \t \t \t \t \t m_layout.setBackgroundResource(R.drawable.mairie01); \t \t \t \t \t \t \t m_layout.setHorizontalGravity(1); \t \t \t \t \t \t \t setContentView(m_layout); – Stan