2012-04-06 2 views
0

hy!センターボタンが水平に動作しません

ボタンを水平に中央に配置したいが、これは決して機能しない。

マイレイアウト:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 


    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/minage" 
     android:layout_alignParentLeft="true" 
     android:padding="5dp" /> 

    <TextView 
      android:id="@+id/ml_minage_value" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:padding="5dp"/> 

    </RelativeLayout> 


    <SeekBar 
     android:id="@+id/ml_minage" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:max="100" 
     style="@style/NFFSeek" 
     android:progressDrawable="@drawable/myseekbar" 
     android:layout_margin="5dp" /> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/maxage" 
     android:padding="5dp"/> 
    <TextView 
      android:id="@+id/ml_maxage_value" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:padding="5dp" /> 

    </RelativeLayout> 

    <SeekBar 
     android:id="@+id/ml_maxage" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     style="@style/NFFSeek" 
     android:progressDrawable="@drawable/myseekbar" 
     android:layout_margin="5dp" /> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/distance" 
     android:padding="5dp" /> 

    <TextView 
      android:id="@+id/ml_distance_value" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:padding="5dp" /> 
    </RelativeLayout> 

    <SeekBar 
     android:id="@+id/ml_distance" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     style="@style/NFFSeek" 
     android:progressDrawable="@drawable/myseekbar" 
     android:layout_margin="5dp" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/gender" 
     android:padding="5dp" /> 

    <RadioGroup 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:checkedButton="@drawable/rbon" > 

     <RadioButton 
      android:id="@+id/ml_female" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:button="@drawable/rbselector" 
      android:checked="true" 
      android:drawablePadding="10dp" 
      android:text="@string/rb_female" 
      android:textColor="#000000" 
      android:paddingLeft="42dp" /> 

     <RadioButton 
      android:id="@+id/ml_male" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/rb_male" 
      android:button="@drawable/rbselector" 
      android:layout_margin="5dp" 
      android:textColor="#000000" 
      android:paddingLeft="42dp" 
      /> 
    </RadioGroup> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

    <Button 
     android:id="@+id/ml_stbutton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="15dp" 
     android:background="@drawable/custom_button" 
     android:layout_alignParentBottom="true" 
     android:layout_centerInParent="true" 
     android:layout_alignParentTop="true" 
     android:gravity="center" 
     android:padding="10dp" 
     android:text="Flirt" 
     android:textColor="#ffffff" 
     android:textSize="12pt" 
     android:typeface="serif" /> 

    </RelativeLayout> 

</LinearLayout> 

このXMLは助けてください真ん中のボタンを適合しません。

enter image description here

答えて

1

問題はRelativeLayoutは、ページの幅をまたがらないということです、それは幅がwrap_contentあるのです。ボタンはRelativeLayoutの中央に配置されていますが、そのレイアウトはボタンの幅と同じで、画面の左側にマッシュアップされています。

RelativeLayoutの幅をmatch_parentとします。

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    ... 
0
<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

    <Button 
     android:id="@+id/ml_stbutton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="15dp" 
     android:background="@drawable/custom_button" 
     android:layout_centerInParent="true" 
     android:gravity="center" 
     android:padding="10dp" 
     android:text="Flirt" 
     android:textColor="#ffffff" 
     android:textSize="12pt" 
     android:typeface="serif" /> 

    </RelativeLayout> 
0

これはあなたの質問には直接言及していませんが、ビューの階層は複雑すぎます。 LinearLayoutRelativeLayoutのすべての要素を、全体にまたがる単一のRelativeLayoutに置き換えることをお勧めします。

関連する問題