如何使LinearLayout可滚动?

时间:2010-10-29 20:12:58

标签: android android-linearlayout

我在屏幕上有很多项目,我需要使用滚动条,以便用户可以向下滚动。但是,滚动要么不可见,要么不起作用。如何将滚动条添加到LinearLayout

10 个答案:

答案 0 :(得分:430)

<ScrollView>

包裹线性布局

See here for an example:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout 
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       xmlns:android="http://schemas.android.com/apk/res/android">
       <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <LinearLayout 
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:orientation="vertical">
                  <!-- Content here -->
            </LinearLayout>
      </ScrollView>
 </LinearLayout>

答案 1 :(得分:137)

<ScrollView 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/scroll" 
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

      <LinearLayout 
            android:id="@+id/container"
            android:orientation="vertical" 
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
      </LinearLayout>

 </ScrollView>

答案 2 :(得分:4)

以下是我通过反复试验的方式。

ScrollView - (外包装)。

 LinearLayout (child-1).

      LinearLayout (child-1a).

      LinearLayout (child-1b

由于Scrollview只能有一个孩子,因此该孩子是一个线性布局。然后,所有其他布局类型出现在第一个线性布局中。我还没有尝试过包含相对布局,但是他们让我疯了,所以我会等到我的理智回归。

答案 3 :(得分:3)

可以使用标记SELECT roles.id as roleID, (SELECT name FROM permissions WHERE permissions.id = 1) as roleName, permissions.id as permissionID, permissions.name as permissionName FROM permissions LEFT JOIN roles ON roles.permissionId = permissions.id WHERE roles.id = 1; 完成此操作。对于 ScrollView ,有一件事需要提醒, ScrollView必须有一个孩子

如果您希望完整布局可滚动,请在顶部添加<ScrollView>。请查看下面给出的示例。

<ScrollView>

但如果您希望布局的某些部分可滚动,则在该部分中添加<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scroll" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!-- Content here --> </LinearLayout> </ScrollView> 。请查看下面给出的示例。

<ScrollView>

答案 4 :(得分:1)

您需要使用以下属性并将其括在线性布局

<LinearLayout ...>
<scrollView ...> 

</scrollView>
</LinearLayout>

答案 5 :(得分:1)

您需要使用滚动视图包装线性布局

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout 
        android:id="@+id/container" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


    </LinearLayout>
</ScrollView>

答案 6 :(得分:0)

resultsBoard.findElements(By.css(mySelector)).then(function(elements) {
  elements.forEach(function(val, idx) {
    elements[idx].getText().then(function(text) {
        console.log(text);
    });
  });
});

答案 7 :(得分:0)

您需要将ScrollView作为布局文件的第一个子项,现在将您的linearlayout放入其中。现在,android将根据可用的内容和设备大小决定是否显示可滚动。

确保linearlayout没有兄弟,因为ScrollView不能有多个子节点。

答案 8 :(得分:0)

每当要使布局可滚动时,都可以将<ScrollView>与其中的布局或组件一起使用。

答案 9 :(得分:-28)

您可以在linearLayout中添加属性:android:scrollbars="vertical"