【问题标题】:LinearLayout not scrolling with ScrollViewLinearLayout 不使用 ScrollView 滚动
【发布时间】:2015-06-04 17:02:02
【问题描述】:

我有一个 LinearLayout,它以编程方式放入了很多 TextView。我的意思是说它超出了我的屏幕底部。我想使用 ScrollView 来允许用户滚动到屏幕之外并查看 TextView 的其余部分。这是我目前的activity_main.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:id="@+id/ll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="61dp"
    android:orientation="vertical" >
</LinearLayout>

</ScrollView>

任何帮助将不胜感激!谢谢!

【问题讨论】:

  • 太棒了!但是您遇到的具体问题是什么?
  • 首先使用 match_parent 属性作为线性布局的高度和宽度......然后显示你的代码,这样我们就可以知道你尝试了什么......
  • 使用 match_parent 作为 ScrollView 的高度。

标签: android android-layout


【解决方案1】:

尝试将android:layout_width="wrap_content" 更改为android:layout_width="match_parent"

<LinearLayout
    android:id="@+id/ll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="61dp"
    android:orientation="vertical" >
</LinearLayout>

</ScrollView>

【讨论】:

  • Jep,让身高 match_parent
【解决方案2】:

如下更改您的代码!

<?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="match_parent" >

<LinearLayout
    android:id="@+id/ll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="61dp"
    android:orientation="vertical" >

</LinearLayout>

</ScrollView>

注意: 要查看它是否正在滚动,请尝试在 linearLayout 中放置一些视图,例如 buttons,否则您不会注意到屏幕滚动

【讨论】:

    【解决方案3】:

    你也可以这样做。效果很好。

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollData"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical" >
    
    
    
         <LinearLayout
            android:id="@+id/linearWhere"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:orientation="vertical"
            android:padding="5dp">
    
          </LinearLayout>
    </ScrollView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2013-07-15
      相关资源
      最近更新 更多