2012-02-27 3 views
1

저는 초보자 용 Android 프로그래머입니다. 버전 별 앱 테이블 변경 사항을 표시하는 활동을 만들도록 지정되었습니다. 표에는 ID, 유형, 설명 및 버전의 네 열이 있습니다.TableRow의 열은 간격 요소가 아닌 가중치 및 무게를 사용하여 나누어졌습니다.

이렇게하려면 scrollView에 TableLayout을 배치했습니다. 그런 다음 런타임에 동적으로 비정상적으로 증가하는 TableRows에 대한 템플릿이 있습니다. 열 너비는 고정 된 상태를 유지해야합니다. 폭이 아니라 높이에서 넘칠 수 있습니다.

이 작업을 수행하기 위해 각각 열 및 행 컨테이너의 weight : & weight : sum 속성을 사용해 보았습니다. (layout_width를 둘 다 0으로 설정했습니다).

문제는 열이 화면 경계 밖으로 확장되고 있다는 것입니다. 이미지를 게시 하겠지만 권한은 없습니다.

(풍경이 가까이 보이지만 바깥 쪽 경계가 여전히 잘리고 있음을 알 수 있습니다.)

아이들의 체중이 전체 체중의 약 45 %에 더해지면 가중치가 제대로 보이게됩니다.

마지막으로 열을 구분하는보기의 무게는 0이고 1dip 너비입니다. (그게 문제를 일으킬 수 있는지 모르겠습니다).

어떤 조언이 필요합니까?

내게는 가중치가 가로 모드 인 것처럼 너비를 사용하는 것처럼 보입니다. 인물 사진과 풍경 사진의 두 가지 레이아웃을 만들어야합니까?

나는 테이블 행에 대한 XML 레이아웃을 추가했습니다 :

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/table_row_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <View 
      android:id="@+id/top_border" 
      android:layout_width="match_parent" 
      android:layout_height="1dip" 
      android:background="#FFFFFF" /> 

     <LinearLayout 
      android:id="@+id/horizontal_container" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="4" > 

      <View 
       android:id="@+id/view1" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_id" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Id" android:textSize="10sp" android:layout_weight="0.5"/> 

      <View 
       android:id="@+id/view2" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_type" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Type" android:textSize="10sp" android:layout_weight="1"/> 

      <View 
       android:id="@+id/view3" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_desc" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Description" android:textSize="10sp" android:layout_weight="2"/> 

      <View 
       android:id="@+id/view4" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_version" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Version" android:textSize="10sp" android:layout_weight="0.5"/> 

      <View 
       android:id="@+id/view6" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 
     </LinearLayout> 

     <View 
      android:id="@+id/view7" 
      android:layout_width="match_parent" 
      android:layout_height="1dip" android:background="#FFFFFF"/> 

    </LinearLayout> 

</TableRow> 

상하 뷰 상단과 하단 경계입니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" android:scrollbarAlwaysDrawVerticalTrack="true"> 

    <ScrollView 
     android:id="@+id/view_scroll" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:fillViewport="true"> 

     <TableLayout 
      android:id="@+id/table_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:shrinkColumns="0" 
      android:stretchColumns="0" > 
     </TableLayout> 

    </ScrollView> 

</LinearLayout> 
+1

당신은 참조 할 수 있도록 행 레이아웃을 추가 할 수 있습니까? 또한, 개별 가중치의 합이 실제로 ['android : weightSum'] (http://developer.android.com/reference/android/widget/LinearLayout)에 지정된 값을 초과하지 않는지 다시 한 번 확인합니다. html # attr_android : weightSum) (이 속성을 참조 할 때 오타가 있다고 가정합니다). –

답변

1

감사 MH :

그리고 여기는 너무 추가하기 테이블의 레이아웃입니다.

다시 연락하지 않으셔서 죄송합니다. (저는 Android와 Stack Overflow가 처음이었습니다 ... 당신이 내 질문에 답했다는 것을 몰랐습니다.) 행 레이아웃을 추가했습니다.

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/table_row_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <View 
      android:id="@+id/top_border" 
      android:layout_width="match_parent" 
      android:layout_height="1dip" 
      android:background="#FFFFFF" /> 

     <LinearLayout 
      android:id="@+id/horizontal_container" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="4" > 

      <View 
       android:id="@+id/view1" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_id" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Id" android:textSize="10sp"  android:layout_weight="0.20"/> 

      <View 
       android:id="@+id/view2" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_type" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Type" android:textSize="10sp" android:layout_weight="0.5"/> 

      <View 
       android:id="@+id/view3" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_desc" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Description" android:textSize="10sp" android:layout_weight="1"/> 

      <View 
       android:id="@+id/view4" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_version" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Version" android:textSize="10sp" android:layout_weight="0.25"/> 

      <View 
       android:id="@+id/view6" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 
     </LinearLayout> 

     <View 
      android:id="@+id/view7" 
      android:layout_width="match_parent" 
      android:layout_height="1dip" android:background="#FFFFFF"/> 

    </LinearLayout> 

</TableRow> 

데이비드

관련 문제