滚动型不显示顶端部分 [英] ScrollView doesn't show top part

查看:140
本文介绍了滚动型不显示顶端部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:滚动型隐藏其子视图的顶部,当它增长超过一定的高度

Problem : ScrollView hides top part of its child view when it grows beyond certain height.

我有以下布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:id="@+id/commandPanel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:paddingLeft="5dip"
        android:paddingRight="5dip" >

        <Button
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="OK" />

        <Button
            android:id="@+id/button2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Back" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/mainContentPanel"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/commandPanel"
        android:background="@android:color/white" >

        <ScrollView
            android:id="@+id/formScrollView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_marginTop="5dip"
            android:layout_weight="1"
            android:background="@android:color/darker_gray"
            android:fillViewport="false"
            android:paddingBottom="5dip"
            android:scrollbarStyle="insideOverlay" >

            <LinearLayout
                android:id="@+id/formContentLayout"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:layout_marginTop="20dip"
                android:background="@android:color/black"
                android:gravity="center_horizontal|top"
                android:orientation="vertical"
                android:paddingLeft="5dip"
                android:paddingRight="5dip"
                android:paddingTop="20dip" >

                <LinearLayout
                    android:id="@+id/tr"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dip"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/title"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="sample title" />

                    <TextView
                        android:id="@+id/value"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="sample value ......." />
                </LinearLayout>
            </LinearLayout>
        </ScrollView>
    </RelativeLayout>

</RelativeLayout>

---------- code ------

---------- code ------

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.scrollview);
    updateUi();
}

//add few more rows here
void updateUi() {
    LinearLayout sampletr = (LinearLayout) findViewById(R.id.tr);
    LinearLayout contentPane = (LinearLayout) findViewById(R.id.formContentLayout);
    TextView title = (TextView) findViewById(R.id.title);
    TextView value = (TextView) findViewById(R.id.value);
    for (int i = 0; i < 25; i++) {
        LinearLayout tr = new LinearLayout(this);
        TextView t = new TextView(this);
        t.setText("Sample title : " + i);
        TextView v = new TextView(this);
        v.setText("Sample value : " + i);

        tr.addView(t, title.getLayoutParams());
        tr.addView(v, value.getLayoutParams());
        contentPane.addView(tr, sampletr.getLayoutParams());
    }
}

在的LinearLayout(滚动型的直接子)这顶行开始,如果没有从上消失。行的增长超过15!而且我甚至不能手动滚动查看它们,任何指针请,有什么不对的布局?

Here top rows in LinearLayout (ScrollView's immediate child) start disappearing from top if no. of rows grows more than 15! Moreover I can not even scroll up manually to view them, Any pointer please, what's wrong with this layout?

推荐答案

好吧,我从的LinearLayout(滚动型的直接子)删除以下行解决了这个问题。

ok, I've solved it by removing following line from LinearLayout (Immediate child of ScrollView)

android:layout_gravity="center"

滚动型现在完美的作品。谢谢大家的建议。

ScrollView works perfectly now. Thanks everyone for suggestions.

这篇关于滚动型不显示顶端部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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