gpt4 book ai didi

android - 水平滚动在 android 的表格布局中不起作用

转载 作者:行者123 更新时间:2023-11-30 01:19:42 25 4
gpt4 key购买 nike

我有一个定义了 5 列的表格布局。但是由于第二列中的文本较大,内容超出了屏幕。所以我试图放置一个水平滚动条。却无能为力。我有一个以 Horizo​​ntalScrollView 作为父级的 TableLayout。布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Balance_Inquiry" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal" >

<HorizontalScrollView
android:id="@+id/horizontalView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dip"
android:scrollbars="horizontal|vertical" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >

<TableLayout
android:id="@+id/table_layout_balance_inquiry"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:stretchColumns="0,1,2,3,4,5" >
</TableLayout>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>

现在我将数据添加到这个表格布局中,如下所示:

private void addHeader() {
// TODO Auto-generated method stub
TableRow tr_head = new TableRow(this);
tr_head.setId(10);
tr_head.setBackgroundColor(getResources().getColor(R.color.bg_login));
tr_head.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));

TextView labelSrNo = new TextView(this);
labelSrNo.setId(20);
labelSrNo.setText("SL NO.");
labelSrNo.setTextColor(Color.WHITE);
labelSrNo.setPadding(5, 5, 5, 5);
tr_head.addView(labelSrNo);// add the column to the table row here

TextView labelACCNO = new TextView(this);
labelACCNO.setId(21);// define id that must be unique
labelACCNO.setText("ACC NO."); // set the text for the header
labelACCNO.setTextColor(Color.WHITE); // set the color
labelACCNO.setPadding(5, 5, 5, 5); // set the padding (if required)
tr_head.addView(labelACCNO); // add the column to the table row here

TextView labelACCTYPE = new TextView(this);
labelACCTYPE.setId(20);
labelACCTYPE.setText("ACC TYPE");
labelACCTYPE.setTextColor(Color.WHITE);
labelACCTYPE.setPadding(5, 5, 5, 5);
tr_head.addView(labelACCTYPE);// add the column to the table row here

TextView labelAVAILBLNCE = new TextView(this);
labelAVAILBLNCE.setId(21);// define id that must be unique
labelAVAILBLNCE.setText("AVAIL BALANCE"); // set the text for the header
labelAVAILBLNCE.setTextColor(Color.WHITE); // set the color
labelAVAILBLNCE.setPadding(5, 5, 5, 5); // set the padding (if required)
tr_head.addView(labelAVAILBLNCE); // add the column to the table row here

TextView extraBalance = new TextView(this);
extraBalance.setId(21);// define id that must be unique
extraBalance.setText("AVAIL BALANCE"); // set the text for the header
extraBalance.setTextColor(Color.WHITE); // set the color
extraBalance.setPadding(5, 5, 5, 5); // set the padding (if required)
tr_head.addView(extraBalance);

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

但是水平滚动不起作用。如何启用水平滚动?任何建议都有很大帮助。

最佳答案

试试这段代码:-

   <ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<HorizontalScrollView
android:id="@+id/hscrll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">

<TableLayout
android:id="@+id/table_main_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@layout/shape">

</TableLayout>
</LinearLayout>
</HorizontalScrollView>
</ScrollView>

这目前对我有用。

关于android - 水平滚动在 android 的表格布局中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37292831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com