Android TableLayout에서 “colspan”에 해당하는 것은 무엇입니까? | Cell 2

Android에서 TableLayout을 사용하고 있습니다. 지금은 하나의 TableRow에 두 개의 항목이 있고 그 아래에 하나의 항목이있는 TableRow가 있습니다. 다음과 같이 렌더링됩니다.

-----------------------------
|   Cell 1    |  Cell 2     |
-----------------------------
|   Cell 3    |
---------------

내가하고 싶은 것은 셀 3이 두 상단 셀 모두에 걸쳐 늘어나도록 만드는 것이므로 다음과 같습니다.

-----------------------------
|   Cell 1    |  Cell 2     |
-----------------------------
|           Cell 3          |
-----------------------------

HTML에서 COLSPAN을 사용하고 싶습니다 …. Android에서 어떻게 작동합니까?



답변

그것을하는 속성이있는 것 같습니다 :
layout_span

업데이트 :이 속성은 TableRow의 자식에 적용해야합니다. TableRow 자체에는 없습니다.


답변

답을 완성하려면 layout_span 속성을 TableRow가 아닌 ​​자식에 추가해야합니다.

이 스 니펫은 tableLayout의 세 번째 행을 보여줍니다.

<TableLayout>
    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="@string/create" />
    </TableRow>
</TableLayout>

답변

그리고 이것이 당신이 프로그래밍 방식으로하는 방법입니다.

//theChild in this case is the child of TableRow
TableRow.LayoutParams params = (TableRow.LayoutParams) theChild.getLayoutParams();
params.span = 2; //amount of columns you will span
theChild.setLayoutParams(params);

답변

전체 행을 채우려면 layout_weight를 사용해야합니다. 그렇지 않으면 테이블 레이아웃의 왼쪽 또는 오른쪽 열이 채워집니다.

<TableRow
  android:id="@+id/tableRow1"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:layout_weight="1"
            android:text="ClickMe" />

    </TableRow>

답변

어쩌면 이것은 누군가를 도울 것입니다. 나는 해결책을 시도 layout_span했지만 이것이 효과가 없다. 그래서이 트릭으로 문제를 해결했습니다. colspan이 필요한 LinearLayout곳에 대신 사용 TableRow하십시오.


답변

TableRow 요소의 자식 요소에서 android : layout_span 사용


답변

코드로 생성 된 TableRow, Textview 등의 경우 rowspan에 문제가 있습니다. Onimush의 답변이 좋은 것처럼 보이지만 생성 된 UI에서는 작동하지 않습니다.

다음은 작동하지 않는 코드입니다.

            TableRow the_ligne_unidade = new TableRow(this);
            the_ligne_unidade.setBackgroundColor(the_grey);

            TextView my_unidade = new TextView(this);
            my_unidade.setText(tsap_unidade_nom);
            my_unidade.setTextSize(20);
            my_unidade.setTypeface(null, Typeface.BOLD);
            my_unidade.setVisibility(View.VISIBLE);

            TableRow.LayoutParams the_param;
            the_param = (TableRow.LayoutParams)my_unidade.getLayoutParams();
            the_param.span = 3;
            my_unidade.setLayoutParams(the_param);

            // Put the TextView in the TableRow
            the_ligne_unidade.addView(my_unidade);

코드는 정상인 것 같지만 “the_params”의 초기 값에 도달하면 NULL을 반환합니다.

다른 한편으로,이 코드는 매력처럼 작동합니다.

            TableRow the_ligne_unidade = new TableRow(this);
            the_ligne_unidade.setBackgroundColor(the_grey);

            TextView my_unidade = new TextView(this);
            my_unidade.setText(tsap_unidade_nom);
            my_unidade.setTextSize(20);
            my_unidade.setTypeface(null, Typeface.BOLD);
            my_unidade.setVisibility(View.VISIBLE);

            // Put the TextView in the TableRow
            the_ligne_unidade.addView(my_unidade);

            // And now, we change the SPAN
            TableRow.LayoutParams the_param;
            the_param = (TableRow.LayoutParams)my_unidade.getLayoutParams();
            the_param.span = 3;
            my_unidade.setLayoutParams(the_param);

유일한 차이점은 범위를 설정하기 전에 TextRow를 TableRow 내부로 푸시한다는 것입니다. 그리고이 경우 작동합니다. 이것이 누군가를 도울 수 있기를 바랍니다!