FrameLayout 中的可滚动布局

3
我是一位帮助翻译文本的助手。
我有一个FrameLayout在我的安卓应用程序上,但是我不能使这个布局的一部分可滚动...我已经尝试了一些解决方案来解决这个问题,但是我找不到修补程序!实际上,我想在ScrollView标签之间看到可以滚动的LinearLayout(也许不需要LinearLayout)。
这是我的xml:
<FrameLayout 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"
    tools:context="com.robertot.timereport.com.robertot.timereport.Pages.YearlyStatFragment">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

                // Some views to scroll

            </LinearLayout>

        </ScrollView>

        <LinearLayout
            android:id="@+id/bottom_linear"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal"
            android:layout_gravity="bottom"
            style="@android:style/Widget.Holo.Light.ActionBar.Solid">

            <Spinner
                android:id="@+id/spnYearY"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="8dp"/>

            <ImageButton
                android:id="@+id/btnFilter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_search"
                android:background="@null"
                android:layout_weight="1"
                android:layout_gravity="center_vertical"/>

        </LinearLayout>

</FrameLayout>

感谢!:)

您可以尝试使用此 https://dev59.com/0E7Sa4cB1Zd3GeqP69bL - kablu
谢谢!它可以工作,但是还有另一个问题:最后一个LinearLayout(id / bottom_linear)隐藏了可滚动的视图...我该怎么解决?谢谢! - user3449772
3个回答

5

在FrameLayout中,所有的内容视图都是相互叠加的,因此正常情况下,线性布局会隐藏前一个ScrollView的一部分。为什么不使用LinearLayout或RelativeLayout代替FrameLayout呢?


1
感谢@Fernando!我已经解决了我的问题,方法如下:
<LinearLayout 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:orientation="vertical"
    tools:context="com.robertot.timereport.com.robertot.timereport.Pages.YearlyStatFragment">



    <ScrollView
        android:id="@+id/scrollyear"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

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

                //Some views

            </LinearLayout>

    </ScrollView>


        <LinearLayout
            android:id="@+id/bottom_linear"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal"
            android:layout_gravity="bottom"
            style="@android:style/Widget.Holo.Light.ActionBar.Solid">

            <Spinner
                android:id="@+id/spnYearY"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="8dp"/>

            <ImageButton
                android:id="@+id/btnFilter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_search"
                android:background="@null"
                android:layout_weight="1"
                android:layout_gravity="center_vertical"/>

        </LinearLayout>

</LinearLayout>

-1

如果您想要实现滚动效果,可以将需要实现滚动的视图放到一个ScrollView中,示例如下:

<ScrollView android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="#ffffff">

// the views here that you want to make scrollable

</ScrollView>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接