2010-05-13 5 views
3

내 Android 앱에서 탭이 Activity입니다. 탭 중 하나에는 두 개의 TextView과 두 개의 EditText이 있습니다.Android EditText가 나머지 공간을 차지하지 않습니다.

첫 번째 EditText은 한 줄에 불과합니다. 그러나 다른 EditText, android:id="@+id/paste_code"이 나머지 공간을 차지하도록하고 싶지만, 내가 한 일과 관계없이 한 줄만 표시합니다. 화면에 맞을 숫자가 장치에 따라 다르기 때문에 수동으로 줄 수를 설정하고 싶지 않습니다.

다음은 관련 코드입니다. 탭이있는 모든 필요한 구성 요소에 중첩되어 있습니다. Activity.

<ScrollView 
    android:id="@+id/basicTab" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" > 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Paste title" 
      android:layout_weight="0" /> 
     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:hint="@string/paste_title_hint" 
      android:id="@+id/paste_title" 
      android:lines="1" 
      android:gravity="top|left" 
      android:layout_weight="0" /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Paste text" 
      android:layout_weight="0" /> 
     <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:hint="@string/paste_hint" 
      android:id="@+id/paste_code" 
      android:gravity="top|left" 
      android:layout_weight="1" /> 
    </LinearLayout> 
</ScrollView> 

답변

9

, 여기 동안의 검색에 오는 사람들을위한 적절한 수정의 :

첫째, 로맹 가이 안드로이드 개발팀 주소이 잘이 블로그 게시물에서 :

http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/

은 본질적으로, 당신의 ScrollView 필요는 android:fillViewport="true" 속성을 포함합니다.

일이 당신이 여기에 몇 가지 확인할 것을 수행 한 후 작동하지 않는 경우 :

  • 필요 ScrollView (예 : LinearLayout A와) 내부의 레이아웃은 layout_height="wrap_content"
  • 을 가지고 확장 할 뷰 (들)은 layout_weight="1.0" 또는 유사한
을 가져야한다 확장하려는 layout_height="wrap_content"
  • 뷰 (들)이 있어야

    확장하려는 뷰에서 minLines="3" 또는 그와 비슷한 것을 설정하는 것을 잊지 마세요. 너무 크게 축소시키지 않으려면 확대/축소하십시오.

  • +0

    실제로; 그 점에 대해 감사드립니다. 나는 내 문제를 해결 한 다른 질문에 대한 링크로 다른 대답에 댓글을 달았다. – Jamie

    +0

    은 매력처럼 작동합니다! – Damjan

    0

    문제는 ScrollView를 사용함에 따른 것 같습니다. ScrollView를 부모 컨테이너로 사용하여 코드를 테스트 한 결과 동일한 문제가 발생했습니다. 그러나 ScrollView를 LinearLayout으로 바꾸면 두 번째 EditText가 제대로 확장되어 전체 화면을 채 웁니다. 문제는 ScrollView가 안드로이드에 넣은 설정에 관계없이 가장 작은 크기로 줄 이도록 설계되어야한다는 것입니다 : layout_height. 다른 레이아웃으로 실험 해 보았습니다. layout_abovelayout_below을 사용하는 RelativeLayout. 그러나 최대 크기에만 영향을 주며 비어있을 때 크기에는 영향을주지 않습니다. 불행히도, 그게 당신의 문제를 해결하는 방법을 잘 모르겠다는 의미 ... 부모 컨테이너로 ScrollView 아닌 다른 무언가를 사용하여 레이아웃을 재 설계 할 수있는 방법이 있나요? 허용 대답은 완전히 상황을 해결하지 않기 때문에

    +0

    예,이 탭은 ScrollView가 없으면 괜찮을 것입니다. (정확하게 기억한다면) EditTexts에는 자체 스크롤 막대가 있기 때문입니다. LineaLayout으로 놀아 보겠습니다. 감사합니다. . – Jamie

    +0

    또한, http://stackoverflow.com/questions/2033296/android-scrollview-problem에서 안드로이드에 대한 귀하의 진술을 확인했습니다 : layout_height는 아무것도하지 않으며 화면의 나머지 부분을 차지하도록 또 다른 XML 속성을 제공합니다. 그래도 작동하지 않는다면 LinearLayout에 의지 할 것입니다. – Jamie

    관련 문제