2010-06-24 7 views
1

양식을 나타내는 3 개의 열이있는 TableLayout을 가지고 있습니다.TableLayout 열 크기 조정

필수 기호 | 라벨 | 입력 필드.

입력란이 화면의 나머지 너비를 레이블 오른쪽으로 채우 길 원합니다. 지금까지 내가 찾은 유일한 해결책은 다음과 같습니다.

<TableLayout android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:stretchColumns="2"> 
    <TableRow> 
        <TextView android:text="@string/requiredSymbol" 
           /> 
    <TextView android:text="@string/Name" 
           android:textColor="@color/orange" 
           android:gravity="left|center_vertical" 
     /> 
    <EditText android:id="@+id/contactName" 
     android:inputType="text|textPersonName" 
           android:ellipsize="end" 
          android:singleLine="true" 
          android:scrollHorizontally="true" 
          android:maxWidth="1sp" 
          /> 
    </TableRow> 

maxWidth에는 실제로 무시되는 값이 있어야합니다. 그런 다음 stretchColumns 값이 좋게 처리됩니다. EditText의 내용이 그렇지 않으면 화면 테두리 너머의 표를 만들 경우에도 작동합니다 (imho a bug ..).

이것은 현재 잘 작동하지만 나에게 약간의 해킹처럼 보입니다. 더 좋은 방법이 있습니까?

답변

0

정적 XML 파일을 사용하는이 단계에서는 더 좋은 방법이없는 것처럼 보입니다. 그러나 이후 나는 필요한 레이블/아이콘에 대한 별도의 열을 갖지 않도록 레이아웃을 변경하고 각 필드의 TextWatcher 구현과 결합 된 EditText # setError 메시지를 사용하도록 변경했습니다. 어쨌든 훨씬 좋네요.

2

열에 android : layout_weight를 사용해 보시고 TableLayout에 android : stretchColumns를 설정하십시오. TableLayout에 문제가있어서 일방적으로 원하지 않는 텍스트 줄 바꿈을 일으키는 열을 줄이기로 결정했습니다. layout_weight 및 일방적 인 열 수축이 관련되어 있는지 확실하지 않습니다.

0

나는 이것이이 폭 FILL_PARENT과 레이아웃에 추가되는 후 EditText 필드의 width을 받고, 다음이가 MaxWidth을 설정하는 데 사용했다 달성하는 방법.

EditText exampleText = new EditText(this); 
exampleText.setText([Your Text]); 

//This says to fill width, but wrap content for the height 
//So it should expand to whatever you've set the MaxLines to be... 
LayoutParams exampleLP = new LayoutParams(FILL_PARENT, WRAP_CONTENT); 
[Parent].addView(exampleText, exampleLP); 

//Here is where it's actually setting the width. 
exampleText.setMaxWidth(exampleText.getWidth()); 

하지 내가 좋아하는 방식으로,하지만 확실히 믿을 수있다 :

그것은 밖으로 같이보고되어 있습니다.

+0

그럴 수도 있지만 코드 솔루션과 비슷합니다. –

0

EditText를 FrameLayout에 래핑하고 EditText를 match_parent로 설정하여 나머지 너비와 일치하도록 EditText를 얻을 수있었습니다. 이것은 스피너에도 효과가있는 것 같습니다.

<TableLayout 
    android:shrinkColumns="1" 
    android:stretchColumns="1" > 

    <TableRow> 

     <!-- column 0 --> 
     <TextView 
      android:text="some text" /> 

     <!-- column 1 --> 
     <FrameLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"/> 

     </FrameLayout> 

    </TableRow> 

</TableLayout> 
+0

계정에있을 수도 있고 없을 수도있는 필수 기호를 사용하지 않습니다. –