- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想实现一个带分页的 TableLayout
,在第 1 页显示 10 条记录,然后在第 2 页显示下 10 条记录,依此类推...我正在使用 Table Layout但我没有得到所需的结果。使用本教程,表格只是水平增长而不是垂直增长。我如何更改它以便它也垂直增长,然后当记录大小大于 10 时转移到下一页?
代码:
public class Sample extends Activity {
String companies[] = {"Google","Windows","iPhone","Nokia","Samsung",
"Google","Windows","iPhone","Nokia","Samsung",
"Google","Windows","iPhone","Nokia","Samsung","Google","Windows","iPhone","Nokia","Samsung",
"Google","Windows","iPhone","Nokia","Samsung",
"Google","Windows","iPhone","Nokia","Samsung"};
String os[] = {"Android","Mango","iOS","Symbian","Bada",
"Android","Mango","iOS","Symbian","Bada",
"Android","Mango","iOS","Symbian","Bada","Android","Mango","iOS","Symbian","Bada",
"Android","Mango","iOS","Symbian","Bada",
"Android","Mango","iOS","Symbian","Bada"};
TextView companyTV,valueTV,deviceTv,actionTv,dateTv,timeTv,creditTv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// creates the Pagination Layout
PaginationLayout paginationLayout = new PaginationLayout(this);
paginationLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// creates content only for sample
TableLayout table = new TableLayout(this);
//table.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TableRow row = new TableRow(this);
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
table.addView(row);
TableRow row2 = new TableRow(this);
row2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
table.addView(row2);
for (int i=0;i<companies.length;i++)
{
deviceTv = new TextView(this);
deviceTv.setText(companies[i]);
deviceTv.setTextColor(Color.RED);
deviceTv.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
deviceTv.setPadding(5, 5, 5, 5);
row2.addView(deviceTv);
actionTv = new TextView(this);
actionTv.setText(os[i]);
actionTv.setTextColor(Color.GREEN);
actionTv.setPadding(5, 5, 5, 5);
actionTv.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
row2.addView(actionTv); // Adding textView to tablerow.
}
/* for(int i = 0; i< 50;i++){
Button button = new Button(this);
button.setText("Button " + i);
if (i%2==0) {
row.addView(button);
} else {
row2.addView(button);
}
}*/
// add the content in pagination
paginationLayout.addView(table);
// set pagination layout
setContentView(paginationLayout);
}
最佳答案
I have already using Table Layout but not getting my required result using this tutorial it just grow horizontally not vertically
对于 github 上的代码,似乎在 PaginationLayout
上使用 addView
将该 View 添加到 HorizontalScrollView
。在您的代码中,您正在创建一个单个 Tablelayout
并向其添加行,因此您的内容垂直增长是正常的。
您很可能需要自己插入页面,像这样:
// creates the Pagination Layout
PaginationLayout paginationLayout = new PaginationLayout(this);
LinearLayout wrapper = new Linearlayout(this);
paginationLayout.addView(wrapper);
// now create a TableLayout, if the content is bigger then your intended number of rows
// then insert another Tablelayout and so on
TableLayout table = new TableLayout(this);
//table.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
TableRow row = new TableRow(this);
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
table.addView(row);
TableRow row2 = new TableRow(this);
row2.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
table.addView(row2);
wrapper.addView(table); // it will probably don't look good if you don't
// also setup the proper width with LayoutParams
如果您继续添加 TableRows
并且您看到您已经向 table 添加了 10 行,那么创建一个新的 TableLayout
并添加它到包装器 LinearLayout
。
我建议您放弃该库并实现您自己的分页。如果您不了解用户的直接交互(通过触摸),那么设置一个 ViewFlipper
(有两个 View ,两个页面,您将继续翻阅)非常简单,两个按钮位于底部控制分页。如果您还需要触摸交互,请使用 ViewPager
(还有更多工作要做)。
关于android - 带分页的 TableLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15522141/
我有2000条记录,我想在tablelayout中显示产品列表。第一次加载需要显示50条记录,其余记录需要分页显示。 在 onCreate() 中我完成了表格布局:它的动态表格内容 tl = (
已编辑:我自己找到了解决方案。谢谢! 我想为 Android 应用程序创建以下屏幕: 现在我有这个: 使用此代码:
我正在尝试做我的第一个复杂的 GUI,但现在我无法解决这个问题。 前两行的第一列只需要包含标签,而前两行的第二列必须占据剩余空间。 在此快照中,我注意到的问题是第一列比我想要的要大。 这是实现该布局的
当仅添加第一行时,一切顺利,但在添加第二行后,它失败了。 pupils=db.getAllPupilsPupil(); events=db.getAllEvents(); TableLayout ta
我想制作一款类似 Jeopardy 的游戏,为了实现这一目标,我决定使用 TableLayout 布局。这就是我的代码现在的样子: import javax.swing.JButton; import
我在 ListView 中使用 TableLayout。我提供的数据本质上是表格形式的,TableLayout 似乎是确保列按需要排列的好方法。这种方法在大多数情况下都很有效 - 见下文。 所需 Vi
我想发布一张图片来描述这个问题,但显然我在 stackoverflow 方面的声誉还不够,所以我将尝试描述我想要完成的事情。 我有一个包含 5 列的 TableLayout。它们由公司名称、职位编号、
我想实现一个带分页的 TableLayout,在第 1 页显示 10 条记录,然后在第 2 页显示下 10 条记录,依此类推...我正在使用 Table Layout但我没有得到所需的结果。使用本教程
我正在构建一个吉他应用程序。屏幕右侧是指板,左侧是几个按钮。 我用一个充满按钮的表格布局构建了吉他琴颈。没什么特别的。这工作得很好。不过我也想支持平板电脑。 吉他琴颈的宽度必须与每个设备保持一致,并且
在我现有的代码中,我有三个按钮,它们在同一行上水平对齐,但是,我希望这些按钮出现在不同的行上。 现有布局... [-----] [-----] [------] 追求布局... [------] [-
我的表格布局有点问题。 我有两列 专栏 1 |第 2 列 column1 内容是静态的,表示一个属性,例如“位置”,“产品”。第二列使用适配器填充。 我的问题是 TextView 打断了 column
我的目标是从数据库中获取数据,然后在我的应用程序中将其显示为表格。 这是我的代码: public void updateLastExpenses(){ Cursor c = Expense.
我一直在尝试基于 Google Play 商店中名为 Timetable 的应用程序创建一个应用程序。在过去的几天里,我一直在努力解决一个看似简单的问题。基本上,我使用 TableLayout 创建了
我正在努力寻找一种在 TableLayout 中添加和删除可点击按钮的好方法。 所以我目前有一个包含整数和对象的 HashMap。它也随着用户的需要而更新。当用户按下“添加项目”按钮时,我希望它完成向
请参阅下面的屏幕截图,了解平板电脑和手机上的不同结果。 Activity .xml
我有一个包含三列的 TableLayout,代表一个带有 的表单 必填符号 |标签 |输入框。 我希望输入字段填充屏幕右侧标签的剩余宽度。到目前为止,我找到的唯一解决方案是这个
我有一个类,其内容设置为具有几个按钮和一个 TableLayout 的布局。 制作 TableLayout 的真正工作是在一个单独的静态助手类中,它有一个返回所需表格的方法。 但是,表格没有显示。我错
我想在线程中创建一个动态表格布局(因为我有一个巨大的表格并且加载时间很长)。它似乎一直工作到第四行,但在出现错误之后。 我找不到问题出在哪里。在此 java 代码中,已简化表布局以解决问题。 我的ja
大家早上好 我在学习 Android 的道路上还面临着另一个问题。我用 CSV 文件的内容制作了一个动态 TableLayout。我需要当我点击/触摸表格中的一行时,颜色应该改变,然后点击一个按钮获取
是否可以并排显示两个 TableLayout(在 RelativeLayout 中)以使两个表格具有相同的宽度?我只是不知道该怎么做。我已经尝试过将 android:stretchColumns="*
我是一名优秀的程序员,十分优秀!