码迷,mamicode.com
首页 > 其他好文 > 详细

ScrollView的用法,隐藏滚动条

时间:2015-01-16 16:54:52      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:布局   scrollview   layout   

我之前写了一个ScrollView老是报java.lang.IllegalStateException: ScrollView can host only one direct child,意思是说:ScrollView只能有一个子布局,所以用一个布局把你写的布局抱起来就OK,隐藏滚动条。


<pre name="code" class="java"><pre name="code" class="java"><ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none" >//设置隐藏滚动条

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/black" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是左边的"
                    android:textSize="25sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是右边的"
                    android:textSize="25sp" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/black" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是左边的"
                    android:textSize="25sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是右边的"
                    android:textSize="25sp" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/black" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是左边的"
                    android:textSize="25sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是右边的"
                    android:textSize="25sp" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/black" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是左边的"
                    android:textSize="25sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是右边的"
                    android:textSize="25sp" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/black" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是左边的"
                    android:textSize="25sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是右边的"
                    android:textSize="25sp" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/black" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是左边的"
                    android:textSize="25sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是右边的"
                    android:textSize="25sp" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/black" />

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="80dp"
                android:gravity="center"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是左边的"
                    android:textSize="25sp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:gravity="center"
                    android:text="我是右边的"
                    android:textSize="25sp" />
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@android:color/black" />
        </LinearLayout>
    </ScrollView>





效果如下:

技术分享

ScrollView的用法,隐藏滚动条

标签:布局   scrollview   layout   

原文地址:http://blog.csdn.net/u014649598/article/details/42776903

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!