2014-04-29 5 views
0

첫 번째 그림은 고정 크기의 EditText를 보여줍니다. 내가 원하는 것은 높이가 스피너 위에있는 공간을 채우기 위해 조정되어야한다는 것입니다.EditText 높이를 동적으로 조정하십시오.

나는 높이의 크기를 늘릴 수 있지만 다른 화면 크기에 대해 동일하게하고 싶습니다. 주목해야 할 또 하나의 사실은 두 번째 그림의 기능을 보존하기를 원한다는 것입니다. 키보드가 나타나면 스피너가 위로 움직이고 아래쪽에 숨겨지기를 원하지 않습니다.

은 여기

<?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="fill_parent" 
android:orientation="vertical" > 

<Button 
    android:id="@+id/button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/textify" /> 

<ScrollView 
    android:id="@+id/myScrollView" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1" > 

    <LinearLayout 
     android:id="@+id/widget37" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <EditText 
      android:id="@+id/field" 
      android:layout_width="match_parent" 
      android:layout_height="321dp" 
      android:layout_marginTop="10dip" 
      android:hint="@string/text_hint" 
      android:inputType="textAutoCorrect|textMultiLine" 
      android:gravity="left|top" 
      android:singleLine="false" 
      android:scrollHorizontally="false" 
      android:scrollbars="vertical" 
      android:overScrollMode="always" 
      android:textSize="18sp" > 
     </EditText> 
    </LinearLayout> 
</ScrollView> 

<Spinner 
    android:id="@+id/spinner1" 
    android:layout_width="match_parent" 
    android:layout_height="51dp" /> 

</LinearLayout> 

fixed size before

fixed size after

+0

나는 안드로이드에서 텍스트 높이를 동적으로 설정할 수 있는지 확신하지 못합니다. 당신이 할 수있는 일은 서로 다른 디바이스 크기를위한 다른 레이아웃을 생성 한 다음 그 레이아웃에서 텍스트 높이를 적절하게 설정하는 것입니다. – Eenvincible

+0

edittext의'fillviewport'와 layour_weight 및 layout_height (아마도'match_parent'를 사용)를 가지고 놀 필요가 있다고 말하고 싶습니다. – njzk2

+0

@ njzk2 귀하의 제안이 효과가있었습니다! ScrollView의 fillviewport 및 match_parent가 트릭을 수행했습니다. 고맙습니다! – ammoun

답변

0

멍청한 놈 감사하지만 나는 또한 글고 다른 뷰 요소에 따라 조정할 것이라는 희망에 선형 레이아웃에 layout_weight를를 사용하는 것이 좋습니다 . 또는 RelativeLayout으로 전환하고 EditText 하단과 Spinner 상단을 연결하는 것이 어렵지 않을 것입니다.

관련 문제