第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使動(dòng)態(tài)生成的表格布局可滾動(dòng)?

如何使動(dòng)態(tài)生成的表格布局可滾動(dòng)?

繁華開(kāi)滿天機(jī) 2022-05-20 18:27:28
我在 Activity 中有 3 個(gè)片段,在其中兩個(gè)片段中我在 a 中有硬編碼TableLayout,ConstraintLayout表的標(biāo)題和行是使用來(lái)自 MySQL 服務(wù)器的信息動(dòng)態(tài)生成的。鑒于其動(dòng)態(tài)特性,表格能夠溢出頁(yè)面,我希望它可以滾動(dòng)。StackOverflow 上已經(jīng)有多個(gè)問(wèn)題,人們想要一個(gè)可滾動(dòng)的表格,但在這些問(wèn)題中,表格及其數(shù)據(jù)是硬編碼的(不知道這是否相關(guān))。我已經(jīng)嘗試了這些問(wèn)題中提出的解決方案,但它們?cè)谖业淖雷由喜黄鹱饔?。解決方案通常是將TableLayouta包裝起來(lái)ScrollView或使用這兩種方法android:isScrollContainer="1"都不適合我。TableLayout里面ScrollView。用于測(cè)試,ScrollView通常它只是TableLayout.<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".ViewProductLocFragment">    <!-- Rest of the fragment -->    <ScrollView        android:layout_width="0dp"        android:layout_height="0dp"        android:layout_marginStart="8dp"        android:layout_marginTop="16dp"        android:layout_marginEnd="8dp"        android:layout_marginBottom="16dp"        android:layout_weight="1"        android:scrollbars="none"        app:layout_constraintBottom_toTopOf="@+id/menuBar"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toBottomOf="@+id/view">        <TableLayout            android:id="@+id/tableLayout"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginStart="5dp"            android:layout_marginTop="5dp"            android:layout_marginEnd="5dp"            android:layout_marginBottom="5dp"            android:stretchColumns="*"            app:layout_constraintBottom_toTopOf="@+id/menuBar"            app:layout_constraintEnd_toEndOf="parent"            app:layout_constraintStart_toStartOf="parent"            app:layout_constraintTop_toBottomOf="@+id/view">        </TableLayout>    </ScrollView></android.support.constraint.ConstraintLayout>
查看完整描述

2 回答

?
嚕嚕噠

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊

您可以使用TableView 庫(kù)使您的表格可滾動(dòng)使用動(dòng)態(tài)數(shù)據(jù)。鏈接如下:-
https://github.com/evrencoskun/TableView


查看完整回答
反對(duì) 回復(fù) 2022-05-20
?
月關(guān)寶盒

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊

我已經(jīng)嘗試通過(guò) Activity 實(shí)現(xiàn)您的代碼。我發(fā)布了我的 Activity 和 XML 代碼供您參考,您能否查看完整代碼中缺少的內(nèi)容,以便提供幫助。


MainActivity.java


public class MainActivity extends Activity {


TableLayout tableLayout;


@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);


    initializeTableLayout();


}



@Override

protected void onResume() {

    super.onResume();


    fillTable();

}


private void fillTable() {

    Integer count = 0;

    for (int i = 0; i < 100; i++) {


        String barcode = "#0000000000";

        String location = "Location";

        Integer quantity = 1;


        TableRow tableRow = new TableRow(MainActivity.this);

        if (count % 2 != 0) {

            tableRow.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));

        }

        tableRow.setId(View.generateViewId());

        tableRow.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));


        TextView labelBarcode = new TextView(MainActivity.this);

        labelBarcode.setId(View.generateViewId());

        labelBarcode.setGravity(Gravity.CENTER);

        labelBarcode.setTextColor(getResources().getColor(R.color.colorAccent));

        labelBarcode.setTextSize(18);

        labelBarcode.setText(barcode);

        tableRow.addView(labelBarcode);


        TextView labelLocation = new TextView(MainActivity.this);

        labelLocation.setId(View.generateViewId());

        labelLocation.setGravity(Gravity.CENTER);

        labelLocation.setTextColor(getResources().getColor(R.color.colorAccent));

        labelLocation.setTextSize(18);

        labelLocation.setText(location);

        tableRow.addView(labelLocation);


        TextView labelQuantity = new TextView(MainActivity.this);

        labelQuantity.setId(View.generateViewId());

        labelQuantity.setGravity(Gravity.CENTER);

        labelQuantity.setTextColor(getResources().getColor(R.color.colorAccent));

        labelQuantity.setTextSize(18);

        labelQuantity.setText(quantity.toString());

        tableRow.addView(labelQuantity);


        tableLayout.addView(tableRow, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        count++;

    }

}


private void initializeTableLayout() {

    tableLayout = this.findViewById(R.id.tableLayout);

    TableRow tr_head = new TableRow(MainActivity.this);

    tr_head.setId(View.generateViewId());

    tr_head.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));

    tr_head.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));


    TextView label_barcode = new TextView(MainActivity.this);

    label_barcode.setId(View.generateViewId());

    label_barcode.setText("BARCODE");

    label_barcode.setTextSize(20);

    label_barcode.setTextColor(Color.BLACK);

    label_barcode.setGravity(Gravity.CENTER);

    tr_head.addView(label_barcode);// add the column to the table row here


    TextView label_location = new TextView(MainActivity.this);

    label_location.setId(View.generateViewId());// define id that must be         unique

    label_location.setText("LOCATION"); // set the text for the header

    label_location.setTextSize(20);

    label_location.setTextColor(Color.BLACK); // set the color

    label_location.setGravity(Gravity.CENTER);

    tr_head.addView(label_location); // add the column to the table row here


    TextView label_quantity = new TextView(MainActivity.this);

    label_quantity.setId(View.generateViewId());// define id that must be         unique

    label_quantity.setText("QTY"); // set the text for the header

    label_quantity.setTextSize(20);

    label_quantity.setTextColor(Color.BLACK); // set the color

    label_quantity.setGravity(Gravity.CENTER);

    tr_head.addView(label_quantity); // add the column to the table row here


    tableLayout.setScrollContainer(true);

    tableLayout.addView(tr_head, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

}


}

activity_main.xml


    <?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">


    <ScrollView

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:layout_marginStart="8dp"

        android:layout_marginTop="16dp"

        android:layout_marginEnd="8dp"

        android:layout_marginBottom="16dp"

        android:layout_weight="1"

        android:scrollbars="none">


        <TableLayout

            android:id="@+id/tableLayout"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_marginStart="5dp"

            android:layout_marginTop="5dp"

            android:layout_marginEnd="5dp"

            android:layout_marginBottom="5dp"

            android:stretchColumns="*"

            app:layout_constraintEnd_toEndOf="parent"

            app:layout_constraintStart_toStartOf="parent"></TableLayout>

    </ScrollView>


</android.support.constraint.ConstraintLayout>

我手動(dòng)添加了 100 個(gè)虛擬行來(lái)測(cè)試它的滾動(dòng)行為,并想通知您它完全可以正常工作。您的 Activity 或 Fragment 父代碼中可能存在阻止表格滾動(dòng)的問(wèn)題。


查看完整回答
反對(duì) 回復(fù) 2022-05-20
  • 2 回答
  • 0 關(guān)注
  • 132 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)