Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HorizontalScrollview在android中不工作_Android_Xml_Horizontalscrollview - Fatal编程技术网

HorizontalScrollview在android中不工作

HorizontalScrollview在android中不工作,android,xml,horizontalscrollview,Android,Xml,Horizontalscrollview,我无法向右滑动,水平滚动视图不工作 我在下面提供了XML的预览,我没有java代码,所以我只提供了XML代码 问题:我在谷歌地图片段的顶部有5个按钮,我无法到达第5个按钮,因为horizonalscrollview不工作 以下是xml的预览: 以下是XML: <RelativeLayout android:layout_height="wrap_content" android:layout_width="500dp" xmlns:android="http://

我无法向右滑动,水平滚动视图不工作

我在下面提供了XML的预览,我没有java代码,所以我只提供了XML代码

问题:我在谷歌地图片段的顶部有5个按钮,我无法到达第5个按钮,因为horizonalscrollview不工作

以下是xml的预览:

以下是XML:

<RelativeLayout

    android:layout_height="wrap_content"
    android:layout_width="500dp"
    xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
    android:layout_width="500dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/linearLayout">

    <HorizontalScrollView

        android:layout_width="500dp"
        android:layout_height="50dp"
        android:background="#BEFFB6"
        android:layout_marginTop="0dp"
        android:id="@+id/horizontalScrollView">

        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="50dp" android:orientation="horizontal"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true">


            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Building 1"
                android:id="@+id/p1"
                android:onClick="b1"
                android:layout_above="@+id/place_autocomplete_fragment"
                android:layout_alignParentStart="true" />

            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Building 2"
                android:onClick="b2"
                android:id="@+id/p2"
                android:layout_above="@+id/place_autocomplete_fragment"
                android:layout_alignParentStart="true" />

            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Building 3"
                android:onClick="b3"
                android:id="@+id/p3"
                android:layout_above="@+id/place_autocomplete_fragment"
                android:layout_alignParentStart="true" />

            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Building 5 "
                android:id="@+id/p5"
                android:onClick="b5"
                android:layout_above="@+id/place_autocomplete_fragment"
                android:layout_alignParentStart="true" />

            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="P.E center"
                android:id="@+id/p4"
                android:onClick="pecenter"
                android:layout_above="@+id/place_autocomplete_fragment"
                android:layout_alignParentStart="true" />

        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout>

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="380dp"

        android:layout_height="450dp"
        tools:context="com.sumo.traffic.traffic"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/linearLayout" />


</RelativeLayout>

之所以会出现这种情况,是因为您对容器的宽度使用了静态尺寸,因此容器部分显示在屏幕外。您必须设置相对宽度。在这种情况下,如果您想让
滚动视图
与屏幕一样大,则必须将
匹配父视图
的值设置为第一个
相对视图
的属性
android:layout\u width
、内部的
线性布局
水平滚动视图

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    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:orientation="vertical">

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_marginTop="0dp"
            android:background="#BEFFB6">

            <!-- content -->

        </HorizontalScrollView>
    </LinearLayout>

    <!-- fragment -->

</RelativeLayout>