【问题标题】:Android scrollable layout - views not visible on orientation changeAndroid 可滚动布局 - 视图在方向更改时不可见
【发布时间】:2017-01-21 12:45:29
【问题描述】:

我的 XML 可滚动布局(正在进行中)如下所示:

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

    <ListView
        android:id="@+id/list"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        >
    </ListView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/tvStatus"
            android:text="0 SMS found"
            android:textSize="15sp"
            android:layout_width="120dp"
            android:layout_height="wrap_content"  />
        <Button
            android:id="@+id/btnExport"
            android:layout_width="88dp"
            android:layout_height="wrap_content"
            android:text="Export"
            />
    </LinearLayout>
</LinearLayout>
</ScrollView>

当在测试设备上以纵向模式加载应用程序时,所有视图都会呈现并可见: portrait mode 当设备方向更改为水平时,只有布局的列表视图部分可见(?!?): landscape mode 有人知道这里可能发生了什么吗?谢谢。

【问题讨论】:

  • 不要让滚动视图直接指向 xml。进行线性布局并在其中放入滚动视图
  • 试过了,但这会导致屏幕上只有一行列表视图可见。

标签: java android android-layout android-view android-scrollview


【解决方案1】:

这是你需要的布局:

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

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </ListView>

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

        <TextView
            android:id="@+id/tvStatus"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:text="0 SMS found"
            android:textSize="15sp"/>

        <Button
            android:id="@+id/btnExport"
            android:layout_width="88dp"
            android:layout_height="wrap_content"
            android:text="Export"
            />
    </LinearLayout>

</LinearLayout>

您还可以在构建时查看布局在横向模式下的效果:

【讨论】:

  • 这又快又高效!非常感谢,你是一个节省者:)
【解决方案2】:

您似乎缺少滚动视图的结束标记。

【讨论】:

  • 你是对的,我没有正确粘贴它,但它是在代码中显示的,所以这(不是)问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多