【问题标题】:Missing views in landscape / scrolling view横向/滚动视图中缺少视图
【发布时间】:2017-09-20 05:22:29
【问题描述】:

我创建了一个包含标题和滚动正文的布局。我可以在纵向模式下看到标题,但是当它进入横向模式或者我必须滚动它时,标题丢失了。

我希望标题保持静态,只有正文应该滚动。 左侧为纵向,右侧为横向。

ma​​in_activity.xml

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

    <include layout="@layout/header_inspection"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include layout="@layout/fragment_body"/>

    </ScrollView>
</LinearLayout>

fragment_body.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
              android:orientation="vertical"
             tools:context="my.mimos.fssm.kpkt.layout.Lain2Generik">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/form_background">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@color/form_background">

            <LinearLayout...> //header

            <LinearLayout...> //column item 1

            <LinearLayout...> //column item 2

            <LinearLayout...> //column item 3

            <LinearLayout...> //column item 4

        </Linearlayout>
</LinearLayout>

header_inspection.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="5"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="start"
        android:divider="@drawable/divider_vertical"
        android:orientation="horizontal"
        android:showDividers="middle"
        android:dividerPadding="12dp">

        <TextView
            android:id="@+id/btn_prev"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="end"
            android:padding="@dimen/text_padding"
            android:text="@string/btn_sebelumnya"/>

        <TextView
            android:id="@+id/btn_nxt"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="end"
            android:padding="@dimen/text_padding"
            android:text="@string/btn_seterusnya"/>
    </LinearLayout>

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

        <TextView
            style="@style/marks"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="end"
            android:text="Markah : "/>

        <TextView
            android:id="@+id/cur_marks"
            style="@style/marks"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="start"
            android:text="0"/>

    </LinearLayout>
</LinearLayout>

【问题讨论】:

  • 您的“header_inspection_view”未在此处显示。对吗?
  • @Ankita 是的,我的“header_inspection”视图在横向时丢失。如果我将标题添加到主要活动,那么标题将随之滚动。我希望标题保持静态
  • 尝试将滚动视图放在线性布局中,并为两个尺寸(高度和宽度)设置 match_parent 属性。
  • 我建议你在横向使用两个窗格,这样你的 ui 会看起来很棒
  • @Ankita 问题仍然存在。标题仍然丢失。虽然我已经找到了解决方案。我应该在include 标头中包含layout_heightlayout_width

标签: android xml android-linearlayout screen-orientation android-scrollview


【解决方案1】:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
              android:orientation="vertical"
             tools:context="my.mimos.fssm.kpkt.layout.Lain2Generik">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/form_background">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:background="@color/form_background">

            <LinearLayout...> //header
            <ScrollView                    
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

            <LinearLayout...> //column item 1

            <LinearLayout...> //column item 2

            <LinearLayout...> //column item 3

            <LinearLayout...> //column item 4
</ScrollView>
        </Linearlayout>
</LinearLayout>

尝试将列包裹在滚动视图的一侧,并将标题保持在滚动视图之外

【讨论】:

    【解决方案2】:

    我发现了它的问题。显然我应该在 include 标记中包含layout_heightlayout_width。因此,ma​​in_activity 的正确代码应该是:

    ma​​in_body.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:tools="http://schemas.android.com/tools"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:orientation="vertical"
                  android:padding="@dimen/padding_screenEdge"
                  tools:context="my.mimos.fssm.kpkt.layout.Lain2Generik">
    
        <include layout="@layout/header_inspection"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"/>
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
    
            <include layout="@layout/fragment_lain2_generik"/>
    
        </ScrollView>
    
    
    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2018-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-28
      • 2014-02-26
      • 2012-04-30
      • 1970-01-01
      相关资源
      最近更新 更多