2014-03-02 2 views
0

지원 라이브러리에서 GridLayout을 사용하고 있습니다. 일부 셀에는 플레이어 정보가 들어 있습니다. 두 개의 TextView가있는 선형 레이아웃을 사용합니다. 랩 할 이름 (두 번째 텍스트보기)을 가져올 수 없었습니다.force android TextView to wrap

현재 행동 :

123 
John Cochtousczyon 

원하는 동작 : 그리드에 그를 추가

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/player_id" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:text="test" /> 

<TextView 
    android:id="@+id/player_name" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:ellipsize="end" 
    android:minLines="2" 
    android:scrollHorizontally="false" 
    android:text="testing thisout with extra sauce" 
    android:textSize="18sp" /> 

</LinearLayout> 

및 코드 :

123 
John 
Cochtousczyon 

여기에 현재 셀 레이아웃 XML의 상태입니다 :

lp = (GridLayout.LayoutParams) playerCell.getLayoutParams(); 
    lp.columnSpec = GridLayout.spec(nameCol); 
    lp.rowSpec = GridLayout.spec(nameRow); 
    playerGrid.addView(playerCell, lp); 

이상적으로 이름을 래핑 한 후 가장 넓은 셀의 열 너비를 설정하는 솔루션이 필요합니다. maxEms를 사용하여 원하는 결과에 가까워졌습니다. 그러나 긴 이름을 사용할 때 잘릴 수있는 정도에 대해 가장 필요한 필요 한도의 균형을 유지해야합니다.

P''R'''sa'''ll 거기에 대한 것이 아니라 너비를 해결하기 위해 - 그냥 밖으로 나가보다 똑똑한 모든 사람들 이이 문제를 해결할 경우 부탁드립니다.

답변

1

여기에 더 나은 뭔가를 따라 올 때까지 내가, 지금에 정착 한 내용은 다음과 같습니다 fill_parent, ellipsize END, maxEms 및 maxLines의

<TextView 
    android:id="@+id/player_name" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:ellipsize="end" 
    android:maxEms="4" 
    android:maxLines="2" 
    android:text="testing thisout with extra sauce" 
    android:textSize="18sp" /> 

조합이 날 정도로 가까이 가져옵니다.

0

이렇게하면 도움이되기를 바랍니다. 나는 간단하게 오래된 "\ n"을 사용하여 줄 바꿈했습니다.

+0

제안 해 주셔서 감사합니다 ...이 경우 미리 작성된 문자열이 있으므로 CRLF를 삽입 할 수있는 기회가 없습니다. – ssdscott