【问题标题】:Android ScrollView not scrolling at allAndroid ScrollView根本不滚动
【发布时间】:2015-06-26 07:16:38
【问题描述】:

下面是我的 XML 代码,我想让整个视图滚动,但是它不起作用,请帮忙看看有什么问题;

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

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/app_icon"
    android:layout_marginTop="20dp"
    android:layout_gravity="center_horizontal"/>

<TextView
    android:id="@+id/textView_app_version"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:layout_gravity="center"/>

<TextView
    android:id="@+id/textView_content"
    android:layout_width="match_parent"
    android:layout_marginTop="15dp"
    android:layout_height="386dp"
    android:gravity="center"></TextView>

</LinearLayout>
</ScrollView>

我试过用, android:fillViewport="true"

但无济于事。

【问题讨论】:

  • 该视图适合屏幕,因此根本不会滚动。
  • 那么,我该怎么办?
  • 您的 xml 是正确的,当有更多组件(如 edittext 或 imageviews)时它会自动滚动
  • 但是,我的文本视图有很长的内容,不适合屏幕,在这种情况下它应该滚动,对吧?
  • 让你的滚动视图 layout_width 和 layout_height 为 fill_parent

标签: android android-studio scrollview


【解决方案1】:

ScrollView 是一个FrameLayout,这意味着您应该在其中放置一个子,其中包含要滚动的全部内容;这个孩子本身可能是一个具有复杂对象层次结构的布局管理器。

所以这里你必须采用LinearLayout或RelativeLayout,然后你必须放置不同层次的组件。

Android : buttons not visible in scrollview

这里我已经给出了一些问题的答案,所以你可以按照这个来解决你的问题,清除你的概念。

【讨论】:

    【解决方案2】:

    尝试这样,滚动将一直工作到结束

    <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">
    
         <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >
    
    
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/app_icon"
                    android:layout_marginTop="20dp"
                    android:layout_gravity="center_horizontal"/>
    
                <TextView
                    android:id="@+id/textView_app_version"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:layout_gravity="center"/>
    
                <TextView
                    android:id="@+id/textView_content"
                    android:layout_width="match_parent"
                    android:layout_marginTop="15dp"
                    android:layout_height="386dp"
                    android:gravity="center"/>
    
            </LinearLayout>
        </ScrollView>
    </Relativelayout>
    

    【讨论】:

      【解决方案3】:

      如果ScrollView 适合您的设备屏幕,它将无法滚动,因此请确保ScrollView 中的内容占用的空间大于您的屏幕尺寸。

      【讨论】:

        【解决方案4】:

        systematix 试试这个,你会得到滚动。

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
        
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:src="@mipmap/ic_launcher" />
        
            <TextView
                android:id="@+id/textView_app_version1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="20dp"
                android:text="hello" />
        
            <TextView
                android:id="@+id/textView_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:gravity="center"
                android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
        
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:src="@mipmap/ic_launcher" />
        
            <TextView
                android:id="@+id/textView_app_version"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="20dp"
                android:text="hello" />
        
            <TextView
                android:id="@+id/textView_content1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:gravity="center"
                android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
        
        
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:src="@mipmap/ic_launcher" />
        
            <TextView
                android:id="@+id/textView_app_version2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="20dp"
                android:text="hello" />
        
            <TextView
                android:id="@+id/textView_content3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:gravity="center"
                android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
        
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:src="@mipmap/ic_launcher" />
        
            <TextView
                android:id="@+id/textView_app_version4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="20dp"
                android:text="hello" />
        
            <TextView
                android:id="@+id/textView_content4"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp"
                android:gravity="center"
                android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>
        
        
        </LinearLayout>
        

        【讨论】:

          猜你喜欢
          • 2013-01-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-04-29
          • 2020-01-04
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多