本帖最后由 coxfilur_2008 于 2010-09-02 19:45:33 编辑

解决方案 »

  1.   

    是 mEditText需要动态调整宽度。
    重发一下。 
    public void updateEditTextWidth(int 
                   screenWidth) {
                int editTextWidth = screenWidth;
                if (mNextBtn.getVisibility() == View.VISIBLE) {
                    editTextWidth -= mNextBtn.getWidth();
                    editTextWidth -= mNextBtn.getPaddingLeft();
                    editTextWidth -= mNextBtn.getPaddingRight();
                }
        
                if (mPrevBtn.getVisibility() == View.VISIBLE) {
                    editTextWidth -= mPrevBtn.getWidth();
                    editTextWidth -= mPrevBtn.getPaddingLeft();
                    editTextWidth -= mPrevBtn.getPaddingRight();
                }
                
                editTextWidth -= mSearchBtn.getWidth();
                editTextWidth -= mSearchBtn.getPaddingLeft();
                editTextWidth -= mSearchBtn.getPaddingRight();            editTextWidth -= mEditText.getPaddingLeft();
                editTextWidth -= mEditText.getPaddingRight();
                
                // temp implementation. 无理由地减去50,是因为算得宽度大。
                editTextWidth -= 50;            if (editTextWidth > 0 && mEditText.getWidth() != editTextWidth) {
                    mEditText.setWidth(editTextWidth);
                    mEditText.refreshDrawableState();
                }
            }
      

  2.   

    如果更改xml配置(随便用什么layout,多少layout都行),能达到要求,请告知。谢谢!
      

  3.   

    感觉从布局上来看,可以不使用relativelayout。linearlayout更能满足楼主需要,只需要为每个控件设置
    android:layout_width="0dp"
    android:layout_weight="1"
    就好了。  其中1是由计算得来。贴上修改过的代码,一个思路(没有验证过~~~)
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/fixed_linearLayout_search" 
                    android:layout_height="45dip"                         
                    android:layout_width="fill_parent" 
                    android:paddingLeft="15dip"
                    android:paddingRight="15dip"
                    android:visibility="gone"
                    android:layout_alignParentBottom="true" 
                    android:layout_alignParentLeft="true"            
                    android:orientation="horizontal"                    
                    android:background="@color/solid_white"> 
                <Button android:layout_width="wrap_content" 
                          android:layout_height="wrap_content"
                          android:id="@+id/sub_btn_fixed_previous" 
                          android:textColor="@color/solid_black" 
                          android:layout_centerVertical="true"
                          android:background="@drawable/transparent_background" 
                          android:drawableRight="@drawable/goto_previous" 
                          android:drawablePadding="5dip"
                          android:paddingRight="10dip"
                          android:textAppearance="?android:attr/textAppearanceSmall" >
                  </Button> 
                  <LinearLayout
                   android:layout_width="0dp"
                   android:layout_height="wrap_content"
                   android:layout_weight="1"
                   android:orientation="horizontal"
                   >
                <EditText android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:id="@+id/fixed_search_content" 
                        android:layout_toRightOf="@+id/sub_btn_fixed_previous"
                        android:layout_centerVertical="true">
                </EditText> 
                  <Button android:layout_width="0dp" 
                          android:layout_height="wrap_content"
                          android:layout_weight="1"
                          android:id="@+id/sub_btn_fixed_search" 
                          android:textColor="@color/solid_black" 
                        android:layout_centerVertical="true"
                          android:background="@drawable/transparent_background" 
                          android:drawableRight="@drawable/menu_search" 
                          android:drawablePadding="5dip"
                          android:textAppearance="?android:attr/textAppearanceSmall" >
                  </Button> 
                 </LinearLayout>                          <Button android:layout_width="wrap_content" 
                          android:layout_height="wrap_content"
                          android:id="@+id/sub_btn_fixed_next" 
                          android:textColor="@color/solid_black" 
                        android:layout_centerVertical="true"
                          android:background="@drawable/transparent_background" 
                          android:drawableRight="@drawable/goto_next" 
                          android:drawablePadding="5dip"
                          android:textAppearance="?android:attr/textAppearanceSmall" >
                  </Button> 
    </LinearLayout>
      

  4.   

    android:layout_width="0dp"
    android:layout_weight="1"够精辟的
      

  5.   

    android:layout_weight="1"通过layout_weight设置该控件“权重”,这样该控件就能自动的去适应布局了。用代码去实现,看你上面写的,觉得挺麻烦的。
      

  6.   

    基本可以。可是空隙比较大,就是EditText不能填充它应该填充的右边区域。
    不管是隐藏不隐藏(goto_next , goto_previous )的情况。
    不知道为何?看起来像这样(不会贴图片,写文字表示吧):// 4个View都显示出来的情况:
          Button [小空隙] TextView [比较大的空隙] Button [小空隙] Button// 两个button (goto_next,goto_previous,他们在显示时出于最右和最左)隐藏的情况。
          TextView [比较大的空隙] Button
      

  7.   

    设置权重确实能起到作用。只是edittext的权重到底要设置多大,我不知道。