android - scrollview 在布局 Activity 的底部留下额外的空间

标签 android android-layout android-scrollview

我的 Scrollview在一些 layouts 下留出空间我是android新手,请帮助这里是我的代码:

 <ScrollView     
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollviewdb"     
    android:layout_width="match_parent"    
    android:layout_height="wrap_content" >  
    <LinearLayout    
      xmlns:android="http://schemas.android.com/apk/res/android" 
              android:orientation="vertical"    
              android:layout_width="match_parent"    
              android:layout_height="wrap_content">    
         <TextView        
            android:layout_width="match_parent"   
            android:layout_height="wrap_content"         
            android:textSize="15sp"  
            android:padding="5dp"     
            android:id="@+id/ghavaed_text"/> 
      </LinearLayout>
  </ScrollView>

最佳答案

添加 android:fillViewport在您的 ScrollView 中。

<ScrollView     
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollviewdb"     
    android:fillViewport="true"
    android:layout_width="match_parent"    
    android:layout_height="wrap_content" >  
    <LinearLayout    
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical"    
      android:layout_width="match_parent"    
      android:layout_height="wrap_content">    
         <TextView        
            android:layout_width="match_parent"   
            android:layout_height="wrap_content"         
            android:textSize="15sp"  
            android:padding="5dp"     
            android:id="@+id/ghavaed_text"/> 
    </LinearLayout>
</ScrollView>

正如@Ironman 解释的那样,这背后的原因是,如果 ScrollView 的内容总是和它自己一样高,它就会变得毫无用处。要解决这个问题,您需要使用名为 android:fillViewport 的 ScrollView 属性。 .当设置为 true 时,如果需要,此属性会使 ScrollView 的 subview 扩展到 ScrollView 的高度。当child高于ScrollView时,该属性无效

关于android - scrollview 在布局 Activity 的底部留下额外的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39244094/

相关文章:

android - 向位置管理器添加多个接近警报

java - 重新连接套接字时重复接收消息

android-layout - 用xml中的android上的静态元素定义 ListView ?

android - 以编程方式设置相对布局中 EditText 和 TextView 的位置

Android:如何更改每个元素的 Drawable 资源的颜色?

android - 如何让线性布局占据 ScrollView 的整个空间?

java - 为什么我无法检测到 ScrollView 内的滑动?

android - 更改偏好类别标签颜色背景

java - 如何将绳子切成 fragment 并通过蓝牙发送每个 fragment ?

android - 多行 AutoCompleteTextView 不接受滚动触摸