顶视图中滚动型消失 [英] Top view disappeared in ScrollView

查看:150
本文介绍了顶视图中滚动型消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我动态添加表格布局列表到的LinearLayout。对于我用滚动型,看看哪些被添加到线性布局表的列表。

I am adding list of table layouts to a LinearLayout dynamically. For that I used ScrollView to see the list of tables which are added to linear layout.

下面是我的XML code。

below is my xml code.

<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>

来源$ C ​​$ C:

Source code:

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);

}

在上述code,有TextView的在它被用来显示一些文本在屏幕的顶部。我加了3桌线性布局它显示在中间1个图表其次是未来2表与底部一些空白/空画面。如果我增加的表数屏幕下方空白处增加。

In the above code, There is TextView at top of the screen which is used to display some text. I added 3 tables to a linear layout it's showing 1st table from middle followed by next 2 tables with some white space/empty screen at bottom. If I increase number of tables that bottom screen empty space is increasing.

实施例:有5表中一个滚动型,但是它会显示从第2表,该表可能是从表的起始或可能是从表的中间,接着第三,第四Ñ空空间5的表在底部滚动型。

Example: There are 5 tables in a ScrollView, but it will display from 2nd table that might be from table starting or might be from middle of the table, followed by 3rd, 4th n 5th tables with empty space at bottom of the ScrollView.

我也能看到文字,但我加了5桌线性布局内滚动型,当我执行,它会显示来自第二表可能是从表中起动或可能来自中部,其次为第3,第4 ñ5桌空的空间。我有我的依恋屏幕截图。

I can able to see the Text, but I added 5 tables to linear layout inside ScrollView, when I executed that, it will display from 2nd table that might be from table starting or might be from middle, followed by 3rd, 4th n 5th tables with empty space. I have attachment my screen-shots.

请帮我。

屏幕的顶视图

屏幕的底视图

推荐答案

找到了!这是的android:layout_gravity在=center_vertical的LinearLayout 这是罪魁祸首..结果
只是删除,一切都应该罚款。

Found it ! It's the android:layout_gravity="center_vertical" in the LinearLayout that is the culprit..
Just delete this and everything should be fine.

这篇关于顶视图中滚动型消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆