2010-12-02 6 views
0

우선이 게시물은 내 첫 번째 게시물이며 마침내 stackoverflow의 일부가되어 행복합니다. : D동적 성장 너비 AutoCompleteTextView

입력 문자열을 제출하려면 AutoCompleteTextView 오른쪽에있는 단추로 자동 완성 검색을 작성하고 싶습니다. 버튼의 너비, 현지화 또는 맞춤 텍스트 ('검색', '지금 검색'등)가 다를 수 있습니다. 나는 AutoCompleteTextView가 지역화 된 검색 버튼까지 전체적으로 동적으로 커지게하고 싶습니다.

나의 현재 approch 매우 정적이며 난 marginRight 버튼의 폭에 따라 변화 할 :

<RelativeLayout 
android:id="@+id/layout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"> 

<AutoCompleteTextView 
android:id="@+id/searchText" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginRight="70dip" 
android:layout_alignParentLeft="true"/> 

<Button 
android:id="@+id/btn" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Search" 
android:layout_alignParentRight="true"/> 

</RelativeLayout> 

그것이 안드로이드 동적 솔루션을 구하는 것이 가능하다?

최고의 소원으로

, 제프

답변

0

그래, 그건 쉬운 수정합니다. 닫기에 그냥 marginRight 줄을 제거하고 Button과 AutoCompleteTextBox를 교체하여 Button (너비가 설정된 항목)이 먼저 정의 된 다음 Button의 ID 인 toLeftOf에 맞춰진 AutoCompleteTextBox를 설정합니다. 이것은 트릭을 할 것입니다!

<RelativeLayout 
    android:id="@+id/layout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    >  
    <Button 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Search" 
     android:layout_alignParentRight="true" 
     />   
    <AutoCompleteTextView 
     android:id="@+id/searchText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@id/btn" 
     /> 
</RelativeLayout> 
+0

100 % 만족하는 대답! : D – Jeffo

+0

권자, 듣기 좋게! – kcoppock

+0

추가 크레딧을 얻으려면 실제로'alignParentLeft' 행을 그대로 둘 수 있다고 생각합니다. – kcoppock