简体   繁体   English

如何在下面的代码中放置ScrollView?

[英]How do I place a ScrollView in the code below?

Below is my XML code. 下面是我的XML代码。 Where do I place a scrollview attribute on the whole screen because some of my view does not show when I switch to landscape view. 我在整个屏幕上的哪个位置放置了scrollview属性,因为切换到横向视图时某些视图不会显示。

<?xml version="1.0" encoding="utf-8"?>



<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">







    <!--  whole linearlayout vertical begin tag   -->

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/linearLayout">



        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/linearLayoutCalendar"
            android:background="@drawable/border"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:layout_marginLeft="@dimen/activity_buttom_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:layout_margin="10dp"
                android:text="Large Text"
                android:id="@+id/textView" />
            <DatePicker
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/datePicker"
                android:calendarViewShown="false"
                android:datePickerMode="spinner"/>
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="OK"
                android:id="@+id/button" />

        </LinearLayout>


        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/linearLayoutFollowUpRequest"
            android:background="@drawable/border"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:layout_marginLeft="@dimen/activity_buttom_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:text="Large Text"
                android:id="@+id/textView2" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textView3" />

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/linearLayoutBookingRequest"
            android:background="@drawable/border"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:layout_marginLeft="@dimen/activity_buttom_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:text="Large Text"
                android:id="@+id/textView4" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textView5" />

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/linearLayoutOccupancy"
            android:background="@drawable/border"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:layout_marginLeft="@dimen/activity_buttom_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textView6" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textView7" />



        </LinearLayout>






    </LinearLayout>     <!-- Whole linear Vertical layout close tag    -->



    <!-- Whole linear Horizontal layout begin tag    -->
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/linearLayout"
        android:layout_toRightOf="@+id/linearLayout"
        android:layout_toEndOf="@+id/linearLayout"
        android:layout_marginLeft="80dp">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/linearLayout"
            android:layout_toRightOf="@+id/linearLayout"
            android:layout_toEndOf="@+id/linearLayout"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:background="@drawable/border">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Follow Up"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textViewFollowUp" />
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/buttonFollowUp" />




        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/linearLayout"
            android:layout_toRightOf="@+id/linearLayout"
            android:layout_toEndOf="@+id/linearLayout"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:background="@drawable/border">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Events Today"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textViewEventsToday" />
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:text="0"
                android:id="@+id/buttonEventsToday" />




        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/linearLayout"
            android:layout_toRightOf="@+id/linearLayout"
            android:layout_toEndOf="@+id/linearLayout"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:background="@drawable/border">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Bookings Today"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textViewBookingsToday" />
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/buttonBookingsToday" />

        </LinearLayout>



    </LinearLayout>



    <!-- Whole linear horizontal layout close tag    -->


<!--  linear vertical layout for drawer tag start   -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="50dp">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <FrameLayout android:id="@+id/maintcont"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>
        <ListView android:id="@+id/drawerlist"
            android:entries="@array/planets"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:background="#fff"
            >

        </ListView>



    </android.support.v4.widget.DrawerLayout>


</LinearLayout>
</LinearLayout>
<!--  linear vertical layout for drawer tag close   -->




</RelativeLayout>

Below is the normal view 下面是普通视图

普通视图

Land scape view 陆地景观

景观景观

What I want to achieve is to have a scrollview on the whole view so I can scroll down to see all views on landscape. 我想要实现的是在整个视图上都有一个滚动视图,这样我就可以向下滚动以查看景观上的所有视图。 Please note I am using a menu drawer layout is the last on my XML. 请注意,我使用的菜单抽屉布局是XML上的最后一个。 if try placing the scroll view on before the Relative layout, I get the below error 如果尝试将滚动视图放在相对布局之前,则会收到以下错误

java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.

And if I place after the relative layout, it lunches but do not scroll. 如果我将其放置在相对布局之后,它会吃午饭,但不会滚动。

I have been able to resolve the scroll but this is how my drawer is showing. 我已经能够解决滚动问题,但这就是我的抽屉显示的方式。 Intercepting my main view Here is the screen shot 截取我的主视图这是屏幕截图 屏幕截图 And here is my xml 这是我的xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout        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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <FrameLayout android:id="@+id/maintcont"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>
        <ListView android:id="@+id/drawerlist"
            android:entries="@array/planets"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:background="#fff"
            >

        </ListView>



    </android.support.v4.widget.DrawerLayout>


</LinearLayout>














 <ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>


 <RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">












    <!--  whole linearlayout vertical begin tag   -->

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/linearLayout">



        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/linearLayoutCalendar"
            android:background="@drawable/border"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:layout_marginLeft="@dimen/activity_buttom_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:layout_margin="10dp"
                android:text="Large Text"
                android:id="@+id/textView" />
            <DatePicker
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/datePicker"
                android:calendarViewShown="false"
                android:datePickerMode="spinner"/>
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="OK"
                android:id="@+id/button" />

        </LinearLayout>


        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/linearLayoutFollowUpRequest"
            android:background="@drawable/border"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:layout_marginLeft="@dimen/activity_buttom_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:text="Large Text"
                android:id="@+id/textView2" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textView3" />

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/linearLayoutBookingRequest"
            android:background="@drawable/border"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:layout_marginLeft="@dimen/activity_buttom_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:text="Large Text"
                android:id="@+id/textView4" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textView5" />

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/linearLayoutOccupancy"
            android:background="@drawable/border"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:layout_marginLeft="@dimen/activity_buttom_margin">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textView6" />


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Large Text"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textView7" />



        </LinearLayout>






    </LinearLayout>     <!-- Whole linear Vertical layout close tag    -->









    <!-- Whole linear Horizontal layout begin tag    -->
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/linearLayout"
        android:layout_toRightOf="@+id/linearLayout"
        android:layout_toEndOf="@+id/linearLayout"
        android:layout_marginLeft="80dp">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/linearLayout"
            android:layout_toRightOf="@+id/linearLayout"
            android:layout_toEndOf="@+id/linearLayout"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:background="@drawable/border">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Follow Up"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textViewFollowUp" />
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/buttonFollowUp" />




        </LinearLayout>

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/linearLayout"
            android:layout_toRightOf="@+id/linearLayout"
            android:layout_toEndOf="@+id/linearLayout"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:background="@drawable/border">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Events Today"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textViewEventsToday" />
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:text="0"
                android:id="@+id/buttonEventsToday" />




        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/linearLayout"
            android:layout_toRightOf="@+id/linearLayout"
            android:layout_toEndOf="@+id/linearLayout"
            android:layout_marginBottom="@dimen/activity_buttom_margin"
            android:background="@drawable/border">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Bookings Today"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/textViewBookingsToday" />
            <Button
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"
                android:layout_marginLeft="@dimen/activity_buttom_margin"
                android:layout_marginRight="@dimen/activity_buttom_margin"
                android:id="@+id/buttonBookingsToday" />

        </LinearLayout>


    </LinearLayout>

</ScrollView>



    </RelativeLayout>

Please what could be wrong. 请出什么问题。

You can put scroll view just after the <RelativeLayout..> . 您可以在<RelativeLayout..>之后放置滚动视图。 Try this: 尝试这个:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/someid">

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

    <!--  whole linearlayout vertical begin tag   -->

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:id="@+id/linearLayout">
        ...
    </LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM