Programing

Android TableLayout에서 "colspan"에 해당하는 것은 무엇입니까?

lottogame 2020. 7. 4. 10:37
반응형

Android TableLayout에서 "colspan"에 해당하는 것은 무엇입니까?


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);

The only difference is that I push the Textview inside the TableRow before setting the span. And in this case, it works. Hope this will help someone!


I think you need to wrap a layout around another one. Have one Layout list vertically, inside have another one (or in this case, two) list horizontally.

I'm still finding it hard to nicely split interface to 50-50 portion in Android.

참고URL : https://stackoverflow.com/questions/2710793/what-is-the-equivalent-of-colspan-in-an-android-tablelayout

반응형