2012-12-07 4 views
4

수평 방향무게가 지정된 스틱이 왜 고정되지 않습니까?

I은 ​​layout_weight를 함께 5 TableLayout을 (폭 & 높이 wrap_content)를 넣어서 후, weightSum = "5"와 난 의 LinearLayout (폭 & 높이 match_parent)를 가지고 있다고 가정 = "1"이므로 모든 TableLayout은 부모의 1/5입니다. (내 관점에서) 즉 각 TableLayout을에 나는 텍스트 뷰 (폭 & 높이 wrap_content)을 넣어 모든 일이 잘못 후

는하지만, :

텍스트는 그 다음 긴에있는 경우 은 부모 레이아웃 (우리의 경우 TableLayout)을 을 소비하도록 강제하므로 TextView, ellipsize = "end"를 지정 했음에도 불구하고 LinearLayout 부모로부터의 TableLayout의 1/5 비율이 더 이상 존중되지 않습니다.

음 일부 reserch을 수행 한 후 나는 layout_width을 설정하면 (weightSum 같은) 다른 모든 속성보다 강한 것으로 나타났습니다. 내 경우

나는 TableLayout을의 폭 = wrap_content뿐만 아니라 에 layout_weight가 wrap_content이기 때문에 = "1"는하지만, 그것의 내용 이후 소비 경향과 무게를 존중하지를 설정합니다.

누군가 내 솔루션을 어떻게 줄 수 있습니까, 내 테이블 레이아웃은 무게를 존중할 수 있습니까? (왜냐하면 내 레이아웃은 비율을 고려하지 않고 하위 텍스트보기의 길이 이후에 소비하기를 원하지 않기 때문입니다).

감사합니다. 여기 내 코드는 다음과 같습니다.

<!-- my code --> 
< LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:weightSum="5" > 

      <!-- table 1 --> 

      <TableLayout 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="1"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:gravity="center_horizontal" 
        android:ellipsize="end" 
        android:maxLines="1" 
        android:text="test1test2test3test4test5" 
        android:textSize="20dp"/> 

       <TableLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 


       </TableLayout> 
      </TableLayout> 

      <!-- table 2 --> 

      <TableLayout 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="1"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_horizontal" 
        android:text="test" 
        android:textSize="20dp" /> 

       <TableLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 

       </TableLayout> 
      </TableLayout> 

      <!-- table 3 --> 

      <TableLayout 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="1" > 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_horizontal" 
        android:text="test" 
        android:textSize="20dp" /> 

       <TableLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 

       </TableLayout> 
      </TableLayout> 

      <!-- table 4 --> 

      <TableLayout 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="1"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_horizontal" 
        android:text="test" 
        android:textSize="20dp" /> 

       <TableLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 

       </TableLayout> 
      </TableLayout> 

      <!-- table 5 --> 

      <TableLayout 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="1" > 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_horizontal" 
        android:text="test" 
        android:textSize="20dp" /> 

       <TableLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 

       </TableLayout> 
      </TableLayout> 

     </LinearLayout> 

답변

5

외부 TableLayouts의 경우 android : layout_width = "wrap_content"대신에 android : layout_width = "0dp"를 사용하십시오.

android : layout_weight = "1"로 지정하십시오.

자동 크기 조정을 위해 android : weightSum = "5"를 제거하십시오.

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

    <!-- table 1 --> 

    <TableLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ellipsize="end" 
     android:gravity="center_horizontal" 
     android:text="test1 test2 test3 test4 test5" 
     android:textSize="20dp" /> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </TableLayout> 
    </TableLayout> 

<!-- table 2 --> 

    <TableLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="test" 
     android:textSize="20dp" /> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </TableLayout> 
    </TableLayout> 

<!-- table 3 --> 

    <TableLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="test" 
     android:textSize="20dp" /> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </TableLayout> 
    </TableLayout> 

<!-- table 4 --> 

    <TableLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="test" 
     android:textSize="20dp" /> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </TableLayout> 
</TableLayout> 

<!-- table 5 --> 

    <TableLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="test" 
     android:textSize="20dp" /> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </TableLayout> 
    </TableLayout> 

</LinearLayout> 

왜 TableLayout 내부가 비어 있습니까? 당신은 전체 텍스트 다음 안드로이드 설정 보려면 : ellipsize = "없음"을

+0

답장을 보내 주셔서 감사합니다.나는 0 dp에 대해 몰랐고 그 다음에 무게를 설정했지만 멋졌습니다. :) TableLayout 내부에 대해서는 내 미래의 작업을위한 다른 View로 채워질 것입니다. –

0

모든 테이블 레이아웃의 layout_height 및 layout_width를 "fill_parent"로 설정하십시오. 을 입력하면 완료됩니다.

0

당신은 하나 개의 테이블 레이아웃 표 행을 사용하여 모든 다섯 부모를위한 테이블 레이아웃

 ` <TableLayout 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:weightSum="5"/> 
      <TableRow 
         your text 
      /> 
      <TableRow 
         your text 
      /> 
     <TableRow 
         your text 
      /> 
     <TableRow 
         your text 
      /> 
     <TableRow 
         your text 
      /> 
     </TableLayout>` 
3

android:layout_width= "0dp"에 대한 weight_sum를 사용할 수 테이블 레이아웃 대신 "wrap_content"

+1

답변 해 주셔서 감사합니다! 그것은 작동;) –

관련 문제