2012-02-02 7 views
2

enter image description here私は、重力を変更しますが、ボタンの位置が同じ

である私は、重力を変更するとき、それは変更されていない理由を説明することができますしてください。最初に私はそれを変更したときボタンの位置が変更されましたが、今は私は位置を変更することはできません。

main.XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 


    <Button 
     android:id="@+id/button1" 
     android:layout_width="92dp" 
     android:layout_height="0dp" 
     android:layout_gravity="right" 
     android:layout_weight="1" 
     android:text="@string/button1" /> 

</LinearLayout> 
+2

XMLを表示してください。 –

+0

いくつかのコードを投稿してください... – NagarjunaReddy

+0

投稿ur xmlコード... – himanshu

答えて

2

関連レイアウトアンドロイド用セットこのプロパティを:layout_width =のLinearLayout ための "match_parent"(親レイアウト)

+0

ありがとうございます –

+0

これをグラフィカルレイアウトから変更したのはどうしてなぜ自動的に変更されませんでしたか? –

0

私の推測では、あなたがプロパティを設定する必要があるということですfill_parentへの親レイアウトの「layout_width」(ボタンを含むLinearLayout)

1

あなたはビューのレイアウトを設定するボタンの重力を設定しています。たとえば、ボタンにテキストがあり、重心を設定した場合は、テキストをボタンの中心に合わせ、コンポーネントの重力を親に設定するには、親の重力を設定する必要があります。

だからにあなたのコードを変更します。

<?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="wrap_content" 
    android:gravity="right" 
    android:orientation="vertical" > 


    <Button 
     android:id="@+id/button1" 
     android:layout_width="92dp" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/button1" /> 

</LinearLayout> 
関連する問題