TableLayout ScrollView 垂直&水平的

发布于 2024-12-02 10:18:03 字数 1088 浏览 2 评论 0原文

我们如何垂直和滚动设置 ScrollView水平的?我尝试了下面的代码,但它不起作用。

<ScrollView
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:background="@color/red"
 android:scrollbarFadeDuration="1000"
 android:scrollbarSize="12dip" >

   <HorizontalScrollView
     android:id="@+id/horizontalScrollView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >

      <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:collapseColumns="2"
        android:stretchColumns="1" >
    </TableLayout>
</HorizontalScrollView>

<ScrollView >
</ScrollView>

这是我的所有代码:http://pastebin.com/ysRhLMyt

当前屏幕:

在此处输入图像描述

我想始终显示滚动条。

How we can setup ScrollView vertically & horizontally? I tried the below code, but it didn't work.

<ScrollView
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:background="@color/red"
 android:scrollbarFadeDuration="1000"
 android:scrollbarSize="12dip" >

   <HorizontalScrollView
     android:id="@+id/horizontalScrollView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >

      <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:collapseColumns="2"
        android:stretchColumns="1" >
    </TableLayout>
</HorizontalScrollView>

<ScrollView >
</ScrollView>

Here is all my code : http://pastebin.com/ysRhLMyt

Current screen :

enter image description here

I want to display scroll bar always.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

他是夢罘是命 2024-12-09 10:18:03

尝试

  • 设置 android:scrollbarFadeDuration="0"

    <前><代码> 或

  • ScrollView1.setScrollbarFadingEnabled(false);

    <前><代码> 或

  • android:scrollbarFadeDuration="0"

    android:scrollbarAlwaysDrawVerticalTrack="true" 垂直

    android:scrollbarAlwaysDrawHorizo​​ntalTrack="true" 水平

和还有一件事,

请记住,ScrollView 只能有一个子控件,因此我们可以创建一个容器(Linear、relative、Table布局)ScrollView 的子级并将所有控件放入该子级中。

供参考: http://android-pro.blogspot.com/2010/ 02/android-scrollview.html

Try,

  • Set the android:scrollbarFadeDuration="0"

               OR 
    
  • ScrollView1.setScrollbarFadingEnabled(false);

               OR
    
  • android:scrollbarFadeDuration="0" and

    android:scrollbarAlwaysDrawVerticalTrack="true" for vertical

    android:scrollbarAlwaysDrawHorizontalTrack="true" for horizontal

And one more thing,

Remember, the ScrollView can have only one child control, so we can make a container (Linear, relative, Table Layouts) the child of the ScrollView and put all the controls inside this child.

For reference: http://android-pro.blogspot.com/2010/02/android-scrollview.html

つ低調成傷 2024-12-09 10:18:03

嵌套滚动视图不起作用。它与滚动视图触摸处理有关:顶级视图始终消耗所有触摸事件。您必须编写自己的自定义滚动视图。

Nested scroll views doesn't work. It's related to scroll view touch handling: top level view always consume all touch events. You have to write you own custom scroll view.

撩心不撩汉 2024-12-09 10:18:03

下面的代码使水平和垂直滚动视图,
要查看其效果,请首先定义一个 200x 200 dp 周围的区域,并将此代码粘贴到其中。

视图将水平和垂直滚动。

<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarSize="10dp"
android:scrollbars="vertical" >

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />
        </LinearLayout>
    </LinearLayout>
</HorizontalScrollView>

Below code which makes horizontal and vertical scroll view,
To see its effect first define a area around 200x 200 dp and paste this code inside it.

The View will scrolling horizontally as well as vertically.

<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarSize="10dp"
android:scrollbars="vertical" >

<HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />

            <Button
                android:layout_width="300dp"
                android:layout_height="100dp" />
        </LinearLayout>
    </LinearLayout>
</HorizontalScrollView>

风月客 2024-12-09 10:18:03

尝试使用 android:orientation 属性。这可用于水平或垂直:android:orientation="horizo​​ntal"android:orientation="vertical"

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:scrollbarFadeDuration="1000"
      android:scrollbarSize="12dip"
      android:background="@color/red" 
      android:orientation="horizontal">

      <TableLayout android:layout_width="match_parent"  
            android:layout_marginTop="10dp" 
            android:id="@+id/tableLayout1" 
            android:layout_height="wrap_content" 
            android:stretchColumns="1" 
            android:collapseColumns="2">
      </TableLayout>
</ScrollView>

Try using the android:orientation attribute. This can be used for horizontal or vertical: android:orientation="horizontal" or android:orientation="vertical".

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:scrollbarFadeDuration="1000"
      android:scrollbarSize="12dip"
      android:background="@color/red" 
      android:orientation="horizontal">

      <TableLayout android:layout_width="match_parent"  
            android:layout_marginTop="10dp" 
            android:id="@+id/tableLayout1" 
            android:layout_height="wrap_content" 
            android:stretchColumns="1" 
            android:collapseColumns="2">
      </TableLayout>
</ScrollView>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文