【发布时间】:2015-08-06 04:49:32
【问题描述】:
我正在动态地将表格布局列表添加到 LinearLayout。为此,我使用 ScrollView 查看添加到线性布局的表格列表。
下面是我的xml代码。
<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:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:background="@color/white"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RET MASTER SITE REPORTS"
android:paddingBottom="5dp"
android:textColor="@android:color/black"
android:textStyle="bold" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"></LinearLayout>
</ScrollView>
源代码:
layout = (LinearLayout) findViewById(R.id.linearLayout);
for (int i = 0; i < 5; i++) {
if (isColorChange) {
displayDeviceDetails(getColor(R.color.blue), getColor(R.color.lightBlue));
} else {
displayDeviceDetails(getColor(R.color.orange), getColor(R.color.lightOrange));
}
}
//Method which i am calling from loop
private void displayDeviceDetails(int titleColor, int cellColor) {
TableRow row = null;
TableLayout tableLayout = new TableLayout(this);
tableLayout.setPadding(0, 30, 0, 0);
for (int i = 0; i < arr.length; i++) {
row = (TableRow) inflater.inflate(R.layout.child_views, null);
row.setBackgroundColor(titleColor);
TextView tvTitle = (TextView) row.findViewById(R.id.tvRowTitle);
TextView tvText = (TextView) row.findViewById(R.id.tvRowText);
if (i == 0) {
tvText.setVisibility(View.GONE);
tvTitle.setGravity(Gravity.CENTER);
tvTitle.setTextColor(Color.WHITE);
tvTitle.setText(arr[i]);
} else {
changeBgColor(cellColor);
setBgColor(tvTitle);
setBgColor(tvText);
tvTitle.setGravity(Gravity.RIGHT);
tvTitle.setText(arr[i]);
tvText.setText(arr1[i]);
row.setBackgroundColor(titleColor);
}
tableLayout.addView(row);
}
layout.addView(tableLayout);
}
在上面的代码中,屏幕顶部有一个TextView,用于显示一些文本。我在线性布局中添加了 3 个表格,它显示了中间的第一个表格,然后是接下来的 2 个表格,底部有一些空白/空白屏幕。如果我增加底部屏幕空白空间正在增加的表格数量。
示例:ScrollView 中有 5 个表格,但它会从可能从表格开始或可能从表格中间开始的第二个表格显示,然后是第三、第四和第五个表格,底部有空白空间滚动视图。
我可以看到文本,但是我在 ScrollView 内的线性布局中添加了 5 个表,当我执行该操作时,它将从可能从表开始或可能从中间开始的第二个表显示,然后是第三个、第四个n 第 5 桌有空位。我有附件我的屏幕截图。
请帮帮我。
【问题讨论】:
-
插入表格时可能有问题
-
我已经添加了我的源代码。一旦检查。问题仅在于滚动视图。
标签: android scrollview