<RadioGroup
        android:id="@+id/radio_group"
        android:layout_width="match_parent"
改成
<RadioGroup
        android:id="@+id/radio_group"
        android:layout_width="0dip"
        android:layout_weight="1"
试试

解决方案 »

  1.   


    根据1楼和2楼的答案,现在可以实现那样的效果,同时:
    mAddFriendBtn = (ImageButton) findViewById(R.id.topbar_right_btn);
    也没有在影响布局。更改后的topbar.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="wrap_content"
        android:background="@drawable/topbar_bg"
        android:orientation="horizontal" >    <ImageButton
            android:id="@+id/topbar_left_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="10dip"
            android:background="@color/transparent" />    <TextView
            android:id="@+id/top_bar_title"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:textColor="@color/white"
            android:textSize="20sp" />    <RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:visibility="gone" >        <RadioButton
                android:id="@+id/auth_tab"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:checked="true"
                android:gravity="center" />        <RadioButton
                android:id="@+id/original_tab"
                android:layout_width="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:gravity="center" />
        </RadioGroup>    <ImageButton
            android:id="@+id/topbar_right_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="10dip"
            android:background="@color/transparent" />
    </LinearLayout>
    但是为什么出现那样的问题,还是没有搞懂原因
      

  2.   

    上面的RadioGroup的属性android:visibility="gone" 应该放在TextView里,放错位置了
      

  3.   

    如果出现了android:visibility="gone"  你的布局肯定有位置变动,最好android:visibility="invisible" 
      

  4.   

    嗯,我就是让textview或者下面的RadioGroup居中
    至于用第一种方法,为什么导致布局的奇怪改变,这个都还不清除是什么原因
      

  5.   

    这种规则的布局,应该用 LinearLayout
      

  6.   

    你原先radio_group的android_width="match_parent",是它给占据了右边所有的空间,所以看不见右边那个添加按钮了。
      

  7.   

    但我设置了android:layout_toLeftOf="@id/topbar_right_btn"
    同时,如果没有调用mAddFriendBtn = (ImageButton) findViewById(R.id.topbar_right_btn);
    就显示正常的,如果一旦通过它获取这个按钮实例,就占据了右边的空间
      

  8.   

    但我设置了android:layout_toLeftOf="@id/topbar_right_btn"
    同时,如果没有调用mAddFriendBtn = (ImageButton) findViewById(R.id.topbar_right_btn);
    就显示正常的,如果一旦通过它获取这个按钮实例,就占据了右边的空间
    这种奇怪的表现还是跟match_parent和RelativeLayout有关。