【问题标题】:Scrollable layout in FrameLayoutFrameLayout 中的可滚动布局
【发布时间】:2017-08-11 12:06:38
【问题描述】:

我的 Android 应用程序上有一个 FrameLayout,但我无法使此布局的一部分可滚动...我尝试了一些解决方案来解决此问题,但我找不到补丁! 实际上,我希望在 Scrollview 标签之间看到可滚动的线性布局(也许,线性布局不是必需的)。

这是我的 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>

谢谢!! :)

【问题讨论】:

标签: android xml android-layout scroll


【解决方案1】:

在 FrameLayout 中,所有内容视图都是一个在另一个之上,因此正常行为是线性布局隐藏了前一个 Scrollview 的一部分。为什么不使用 LinearLayout 或 RelativeLayout 而不是 FrameLayout?

【讨论】:

    【解决方案2】:

    感谢@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>
    

    【讨论】:

      【解决方案3】:

      您可以使用 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>
      

      【讨论】:

        猜你喜欢
        • 2015-03-21
        • 2016-12-02
        • 2021-06-27
        • 1970-01-01
        • 1970-01-01
        • 2019-05-19
        • 1970-01-01
        • 2011-12-18
        • 1970-01-01
        相关资源
        最近更新 更多