2013-12-14 3 views
0

텍스트 뷰에 텍스트가 올바르게 표시되지 않습니다. 텍스트는 두 행에 걸쳐 있지만 두 번째 텍스트 행은 텍스트의 상반부 만 표시합니다. 마치 height = wrap_content을 사용 했음에도 불구하고 텍스트가 수평으로 2 개로 절단 된 것처럼 보입니다.테이블 레이아웃에 TextView가 올바르게 표시되지 않습니다.

XML 코드 :이 해결

<TableRow 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="15dp" 
     android:weightSum="1" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.4" 
      android:text="No. of direct Reportees:" /> 

     <EditText 
      android:id="@+id/direct" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.6" 
      android:hint="Eg. 12" 
      android:inputType="numberDecimal" 
      android:textAppearance="?android:attr/textAppearanceSmall" > 

      <requestFocus /> 
     </EditText> 
    </TableRow> 

는 :

이 동작은 기본 정렬 예정이다. 컨테이너의 높이가 정확합니다 (두 개의 자식 중 최대 크기). Textview은 단추와 일치하는 기준선이되도록 아래로 이동합니다. 이 동작은 기존 앱의 레이아웃을 유지하기 위해 변경할 수 없습니다. 귀하의 경우이 레이아웃을 구현하는 올바른 방법은 LinearLayout 태그에 android:baselineAligned="false"을 추가하는 것입니다. 그러면 TextView 위의 추가 수직 공간도 제거됩니다.

답변

0

이 동작은 기준선 정렬 때문입니다. 컨테이너의 높이가 정확합니다 (두 개의 자식 중 최대 크기). 그러나 Textview는 단추와 정렬 된 기준선이되도록 아래로 이동합니다. 이 동작은 기존 앱의 레이아웃을 유지하기 위해 변경할 수 없습니다. 귀하의 경우에이 레이아웃을 구현하는 올바른 방법은 LinearLayout 태그에 android : baselineAligned = "false"를 추가하는 것입니다. 이렇게하면 TextView 위의 추가 수직 공간도 제거됩니다.

1

작업 속성 무게를 만들기 위해 LinearLayout 내부 TextViewEditText을 넣어 :

<TableRow 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="15dp"> 
<LinearLayout 
     android:id="@+id/table_row_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 
     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.4" 
      android:text="No. of direct Reportees:" /> 

     <EditText 
      android:id="@+id/direct" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.6" 
      android:hint="Eg. 12" 
      android:inputType="numberDecimal" 
      android:textAppearance="?android:attr/textAppearanceSmall" > 

      <requestFocus /> 
     </EditText> 
</LinearLayout> 
</TableRow> 
+0

오류 발생 : 의심스러운 크기 :보기를 보이지 않게합니다. 아마도 layout_height – Jimmy

+0

에 대한 것이므로 wrap_content 내에서 match_parent를 가져서는 안됩니다. 동시에 나는 테이블 행에서도 체중이 작동한다고 생각합니다. –

+0

무게가 더 일찍 잘 작동했다. – Jimmy

0

을 시도해보십시오 this-

<TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.4" 
     android:text="No. of direct Reportees:" /> 

    <EditText 
     android:id="@+id/direct" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.6" 
     android:hint="Eg. 12" 
     android:inputType="numberDecimal" 
     android:textAppearance="?android:attr/textAppearanceSmall" > 

     <requestFocus /> 
    </EditText> 
</TableRow> 

소스 -

http://www.chess-ix.com/blog/the-use-of-layout_weight-with-android-layouts/

+0

무게가 0dp로 설정된 너비로 작동합니다 –

+0

좋습니다. 무게를 지우면 효과가 있습니까? –

+0

나는 가중치가 필요합니다 ... 그것을 삭제할 수 없습니다 – Jimmy

0

높이가 너비보다 먼저 텍스트보기에 지정된다고 생각합니다.

무게 때문에, 너비는 렌더링시 계산됩니다.

너비가 할당 될 때까지 textview의 높이가 설정되었습니다.

그 textview의 텍스트가 정적 일 것 같아서 하드 코딩 된 높이를 사용 해보십시오.

+0

하드 코드 된 값이 작동하지만 더 나은 해결책을 찾고 ... – Jimmy