【问题标题】:Cannot scroll in android emulator无法在android模拟器中滚动
【发布时间】:2018-04-05 23:31:02
【问题描述】:

当方向为横向时,是否可以使用 android 模拟器滚动?如果是,那我一定是错过了什么……请帮帮我……谢谢

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

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

    <TableLayout

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:stretchColumns="|"
        android:layout_marginBottom="25dp">


    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/tableRow1">

                   .....
  </TableRow>

    </TableLayout>
</LinearLayout>
    </ScrollView>

【问题讨论】:

  • 是的,绝对可以在模拟器和设备上双向滚动
  • Yes 滚动应该可以在模拟器中运行,并且您的代码看起来还可以。在某些设备(旧)中,Scrollview 不允许作为父布局,因此请尝试添加 LinearLayout 作为 xml 的父布局。

标签: java android scroll


【解决方案1】:

是的,这是绝对可能的。您可以添加:android:fillViewport="true"

如果 that 不起作用,则将 LinearLayout(作为父级)包裹在 Scrollview 周围。我希望这对你有用。

请查看此以获取更多信息:
https://developer.android.com/reference/android/widget/ScrollView.html

【讨论】:

  • 如何垂直滚动?
  • @Hoo 告诉我上面的逻辑是否有效?如果不是 Create Linear Layout 作为父级,则设置 Scrollview
  • @Hoo 很高兴听到这个消息。
  • 但是如何垂直滚动而不是水平滚动?
【解决方案2】:

是的滚动应该可以在模拟器中运行,并且您的代码看起来还可以。

在某些(旧)设备/模拟器中,Scrollview 不允许作为父布局,因此请尝试添加 LinearLayout 作为 xml 的父级。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

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

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

          <TableLayout
             ....
          </TableLayout>

     </LinearLayout>

   </ScrollView>

</LinearLayout>

【讨论】:

  • 你知道如何让它垂直滚动吗?
  • ScrollView 总是垂直滚动。
  • 如果我想水平滚动,听起来可行吗?
  • 可以,但是你需要使用HorizontalScrollView而不是ScrollView。如果您想要垂直 水平滚动,请参阅此 question
  • 谢谢...明天我尝试后会给你反馈
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-04
  • 2023-03-04
  • 2015-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多