質問

大丈夫、これだTableLayout、そのデータを見て、的確に指示してくれますの行を追加プログラム.私にとって、TableLayout内のHorizontalScrollView、内ScrollView-これは私にスクロールすることにより、水平、縦方向に配置します。どのようにしているいは追加ヘッダ行かない。たっての移動もすることにより、私のスクロールした実際のTableLayout、TableRowsのHorizontalScrollView;私たがその後の追加ヘッダ行の外部にスクロールす。

どのように思いをは第二のテーブルレイアウトのヘッダー行が列のラインナップしていきそうすることが困難であるとき。そのアイデア?

役に立ちましたか?

解決

その際の一つのアプローチが埋め込むことによりTableLayout内の他のTableLayoutの列のヘッダに、前の行として下記の様になっています。整のデータのヘッダのlayout_widthのヘッダビューオブジェクトと、データのビューするオブジェクトの設定と同じディップ値です。また、layout_weightの内TableLayoutのオブジェットに対応するヘッダを表します。そして、XMLを以下のい3TextViews内TableLayout単一の行を列のヘッダを含みます。ここにあるのはどのように配置することができます。きの移植するデータプログラムにより膨らませたり、吸い込んだレイアウトを追加で行います。

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


  <TableRow>
    <TextView android:text="Name"
        android:layout_width="100dp"        
        android:layout_column="0"
        android:layout_weight="1"/>
    <TextView android:text="Score"
        android:layout_width="30dp"
        android:layout_column="1"
        android:layout_weight="1">
    </TextView>
    <TextView android:text="Level"
        android:layout_width="30dp"
        android:layout_column="2"
        android:layout_weight="1">
    </TextView>
  </TableRow>

    <ScrollView android:layout_height="120dp">      
    <TableLayout android:id="@+id/score_table"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">          
    <TableRow>
        <TextView android:text="Al"
        android:layout_width="100dp"        
        android:layout_column="0"
        android:layout_weight="1">
        </TextView>
        <TextView android:text="1000"
        android:layout_width="30dp"
        android:layout_column="1"
        android:layout_weight="1">
        </TextView>
        <TextView android:text="2"
        android:layout_width="30dp"
        android:layout_column="2"
        android:layout_weight="1">
        </TextView>
    </TableRow>
  </TableLayout>
  </ScrollView>     
</TableLayout>

他のヒント

った別のものを行っています。

でのテーブルは通常のヘッダ行として最初の列内の垂直方向LinearLayout.次に、プログラムの削除最初の行を追加することが最初の子とのLinearLayout.このような魅力です。

編集:これはまた作品なの指定静列幅.

のを知っている問題はもってこいのスポットですので、Googleにしてくれたしていることが特徴となったのと同じ問題です。以来、思いがその場で発音を確認することがでのシーンを、もっとみんなに広めていきたいです。

考:のTableLayout内にありますScrollView)RelativeLayoutをオーバーレイ、そのように描き、最初の(header)が行えます。

こちらはlayout.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/table_wrapper"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
>
    <ScrollView

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        tools:ignore="UselessParent"
    >
        <TableLayout

            android:id="@+id/table"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        />
    </ScrollView>
</RelativeLayout>

このコード:

TableLayout table = (TableLayout)view.findViewById(R.id.table);

final TableRow headerRow = new TableRow(context);
table.addView(headerRow);

table.addView(new TableRow(context));
table.addView(new TableRow(context));
table.addView(new TableRow(context));


RelativeLayout tableWrapper = (RelativeLayout)view.findViewById(R.id.table_wrapper);

View fakeHeaderView = new View(context) {
    @Override
    public void draw(Canvas canvas) {
        headerRow.draw(canvas);
    }
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int width = headerRow.getMeasuredWidth();
        int height = headerRow.getMeasuredHeight();

        widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
};

tableWrapper.addView(fakeHeaderView);

ない方のために幸せを事前に定義するサイズにより、ビットのハッキングの電話をかけてきました。

基本的には、別表のタイトルで過ごトラスト-ホールディングスが、同じトップアライメント、そして作部のタイトルの行を追加した後のトラスト-ホールディング追加その他のタイトルテーブルの子ビューのlayoutParamsに行形のトラスト-ホールディングス.

ここでの私の基本例です。

ごレイアウト:

<HorizontalScrollView
    android:id="@+id/table_horizontal_scroll_view"
    android:layout_alignParentTop="true"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:clickable="false">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >

        <ScrollView
            android:layout_alignParentTop="true"
            android:layout_marginTop="0dp"
            android:id="@+id/table_vertical_scroll_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <TableLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/grid_table_layout"
                />

        </ScrollView>

        <TableLayout
            android:layout_alignLeft="@+id/table_vertical_scroll_view"
            android:layout_alignRight="@+id/table_vertical_scroll_view"
            android:layout_alignStart="@+id/table_vertical_scroll_view"
            android:layout_alignEnd="@+id/table_vertical_scroll_view"
            android:layout_alignParentTop="true"
            android:background="@color/grid_view_background"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/grid_floating_row_layout"
            />

    </RelativeLayout>


</HorizontalScrollView>

そのときに追加の列:

    //clear out any views
    tableLayout.removeAllViews();
    floatingRowLayout.removeAllViews();

    TableRow[] rows = getTableContentRows() // content of your table
    TableRow[] titleRows = {getTitleRow(), getTitleRow()}; //two copies of your title row
    tableLayout.addView(titleRows[0]); // first add the first title to the main table
    addRows(rows) // add any other rows

    floatingRowLayout.addView(titleRows[1]); // floatingRowLayout is connected to id/grid_floating_row_layout

    titleRows[0].setVisibility(View.INVISIBLE); // make the title row added to the main table invisible

    // Set the layoutParams of the two title rows equal to each other. 
    // Since this is done after the first is added to the main table, they should be the correct sizes.
    for(int i = 0; i < titleRows[0].getChildCount(); i++) {
      titleRows[1].getChildAt(i).setLayoutParams(titleRows[0].getChildAt(i).getLayoutParams());
    }

利用tableLayout一ScrollViewのような与 android:stretchColumns="*"

   <RelativeLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:paddingTop="5dp"
            android:layout_height="match_parent"
            android:layout_below="@+id/llSpinner">
            <TableLayout
                android:layout_width="match_parent"
                android:id="@+id/tableHead"
android:stretchColumns="*" 
                android:layout_height="wrap_content">
            </TableLayout>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/tableTotal"
            android:layout_below="@+id/tableHead"
            android:id="@+id/scrolltable">


        </ScrollView>
    <TableLayout
                android:layout_width="match_parent"
                android:id="@+id/tableTotal"
android:stretchColumns="*" 
                android:layout_alignParentBottom="true"
                android:layout_height="wrap_content">
            </TableLayout>
        </RelativeLayout>

それをプレゼンテーションのための行の最も重要なも android:layout_width="0dp"

<TableRow
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:focusable="true"
    android:focusableInTouchMode="false"
    android:clickable="true"
    android:background="@android:drawable/list_selector_background">

    <TextView
        android:text="S.No"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/tbsNo"
        android:layout_weight="1"
        android:gravity="center"
        android:layout_column="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Date"
        android:layout_weight="1"
        android:gravity="center"
        android:id="@+id/tbDate"
        android:layout_column="2" />


    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Count"
        android:layout_weight="1"
        android:gravity="center"
        android:id="@+id/tbMrCount"
        android:layout_column="3" />
</TableRow>

現在の活動

 Tablelayout tableHeading =(TableLayout)findViewById(R.id.tableHead);


               Tablelayout    table =(TableLayout) findViewById(R.id.table_repots);
                   trHeading = (TableRow) getLayoutInflater().inflate(R.layout.table_row_item, null);
                trHeading.setBackgroundColor(Color.parseColor("#6688AC"));
                trHeading.setPadding(0,10,0,10);

                TextView tv;
                tv = (TextView) trHeading.findViewById(R.id.tbsNo);
                tv.setText("S.No");
            tv = (TextView) trHeading.findViewById(R.id.tbDate);
           tv.setText("Date");
          table.addView(tv);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top