2017-05-04 17 views
0

我有我的EditText宽度设置为wrap_content我该如何给我的微调框宽度和我的EditText一样?

<EditText 
      android:id="@+id/reg_password_retype" 
      android:ems="10" 
      android:hint="@string/passwordRetype" 
      android:inputType="textPassword" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent"/> 

和它下面我有我的微调如下:

<Spinner 
      android:id="@+id/states_options" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:background="@drawable/send" 
      android:popupBackground="@android:color/transparent"/> 

我从iOS开发出来,有我们所谓的“宽度相等”的东西,有没有一种方法可以让我设置我的微调器的宽度与我的编辑文本完全相同?

+0

给宽度t o父级布局,使用匹配父级属性,如果没有父级可用创建一个 – Keerthivasan

+0

是否在1布局? – zihadrizkyef

+0

请告诉什么是父布局,如果这是在一个布局 – anddevmanu

回答

1

像iOS中的设置“拖尾& Leading Space”,Android中的EditText和Spinner都设置了相同的“Layout Margin Left and Right”。它可能会解决这个问题。

0

这取决于你的父宽度,你可以实现这样的事情。将微调器宽度更改为match_parent。希望这将解决这个问题。

<LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
<EditText 
     android:id="@+id/reg_password_retype" 
     android:ems="10" 
     android:hint="@string/passwordRetype" 
     android:inputType="textPassword" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent"/> 

     <Spinner 
     android:id="@+id/states_options" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/send" 
     android:popupBackground="@android:color/transparent"/> 

0

通过代码做到这一点 -

findView第一

EditText edt=(EditText)findviewById(R.id.reg_password_retype); 
    Spinner spinner (Spinner)findViewById(R.id.states_options); 
    getWindow().getDecorView().getViewTreeObserver() 
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 
      @Override 
      public void onGlobalLayout() { 
      LayoutParam lp=spinner.getlayoutParam(); 
      lp.width=edt.getWidth(); 
    sippner.setLayoutParam(lp); 
      getWindow().getDecorView() 
.getViewTreeObserver() 
.removeOnGlobalLayoutListener(this); 
      } 
     }); 
1

你可以用它LinearLayout周围有与之相匹配的,例如像这样

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <EditText 
      android:id="@+id/reg_password_retype" 
      android:ems="10" 
      android:hint="@string/passwordRetype" 
      android:inputType="textPassword" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent"/> 

     <Spinner 
      android:id="@+id/states_options" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/send" 
      android:popupBackground="@android:color/transparent"/> 
    </LinearLayout> 


</LinearLayout> 
相关问题