2011-10-31 6 views
0

グラフィックレイアウト上に、上の中央ボタンを表示します。 私のエミュレータのマイボタンは左上隅にあります。エミュレータのグラフィックレイアウトが異なります

私の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 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ファイルを関連付け

答えて

1

私は私のプロジェクトの簡単なクリーンと私の問題を修正しました。

0

Javaコードに正しいレイアウトコンテンツを設定していることを確認してください。

レイアウトの向きを設定しなかった場合、LinearLayoutのデフォルトの向きはHORIZONTALになります。あなたは、プログラムまたは以下のようなmain.xmlファイルを編集して、それを設定することができます。

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

または

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

はい私は正しいレイアウトを設定しました。私のxmlファイルは、main.xmlです。\ [コード] public class mainアクティビティ{ /**アクティビティが最初に作成されたときに呼び出されます。 */ @Override パブリックボイドonCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); [/ code] 私はプログラムで試してみますが、私のループの後にボタンにアクセスする(setTextをexempleにする)方法は? – Stan

+0

私の主な活動はこれで大丈夫です: 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.setHorizo​​ntalGravity(1); \t \t \t \t \t \t \t setContentView(m_layout); – Stan

関連する問題