如何使用Horizo​​ntalScrollView? [英] How to use HorizontalScrollView?

查看:131
本文介绍了如何使用Horizo​​ntalScrollView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序可以水平滚动,因此它可以在页面之间滑动。但是,当我用Android SDK中此功能不会让我的XML布局填充母即它不会让我有一个完整的画面,包括我的按钮和对象。

我如何才能解决这个问题还是什么任何想法是一种替代方法?

这里的code:

 <?XML版本=1.0编码=UTF-8&GT?;
< Horizo​​ntalScrollView的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>    < RelativeLayout的
        机器人:layout_width =348dp
        机器人:layout_height =559dp>        <的ImageButton
            机器人:ID =@ + ID / imageButton1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentBottom =真
            机器人:layout_alignParentLeft =真
            机器人:layout_marginBottom =341dp
            机器人:layout_marginLeft =146dp
            机器人:SRC =@绘制/ ic_launcher/>    < / RelativeLayout的>
< / Horizo​​ntalScrollView>


解决方案

改变相对布局的LinearLayout。类似于垂直滚动型,它利用一个的LinearLayout的。

下面是一个示例布局我在我的项目之一:

 < Horizo​​ntalScrollView
            机器人:ID =@ + ID / horizo​​ntalScrollView1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:滚动条=无>            <的LinearLayout
                机器人:ID =@ + ID / LinearLayout1
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent
                机器人:方向=横向>                <按钮
                     机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:文字=@字符串/ class_tab/>                <按钮
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:文字=@字符串/考试/>                <按钮
                    机器人:ID =@ + ID / button_more
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:文字=@字符串/多/>            < / LinearLayout中>
        < / Horizo​​ntalScrollView>

I want my app to be able to scroll horizontally so it can slide between pages. But when I use this feature on android sdk it won't let me make the xml layout fill parent i.e. it won't let me have a full screen to include my buttons and objects.

Any idea on how can I fix this or what is an alternate method?

Here's the code:

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

    <RelativeLayout
        android:layout_width="348dp"
        android:layout_height="559dp" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="341dp"
            android:layout_marginLeft="146dp"
            android:src="@drawable/ic_launcher" />

    </RelativeLayout>


</HorizontalScrollView>

解决方案

Change the relative layout to LinearLayout. Similar to a vertical ScrollView, it makes use of a LinearLayout.

Here is a sample layout I have in one of my projects:

<HorizontalScrollView
            android:id="@+id/horizontalScrollView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scrollbars="none" >

            <LinearLayout
                android:id="@+id/LinearLayout1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal" >

                <Button
                     android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/class_tab" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/exam" />

                <Button
                    android:id="@+id/button_more"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/more" />

            </LinearLayout>
        </HorizontalScrollView>

这篇关于如何使用Horizo​​ntalScrollView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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