横向/滚动视图中缺少视图
Missing views in landscape / scrolling view
我创建了一个具有 header 和滚动 body 的布局。我可以在纵向模式下看到 header,但是当它进入横向模式或我必须滚动它时,header 不见了。
我希望 header 保持静止,只有 body 应该滚动。
左侧为纵向,right-side 为横向。
main_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>
<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>
try to wrap the columns in side the scrollview and keep the header outside of scrollview
我发现了它的问题。显然我应该在 include 标签中包含 layout_height
和 layout_width
。因此,main_activity的正确代码应该是:
main_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>
我创建了一个具有 header 和滚动 body 的布局。我可以在纵向模式下看到 header,但是当它进入横向模式或我必须滚动它时,header 不见了。
我希望 header 保持静止,只有 body 应该滚动。 左侧为纵向,right-side 为横向。
main_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>
<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>
try to wrap the columns in side the scrollview and keep the header outside of scrollview
我发现了它的问题。显然我应该在 include 标签中包含 layout_height
和 layout_width
。因此,main_activity的正确代码应该是:
main_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>