我创建了一个具有标题和滚动正文的布局。我能够在纵向模式下看到标题,但是当它进入横向模式或者我必须滚动它时,标题丢失了。
我希望标题保持静态,只应滚动主体。 左侧是纵向,右侧是横向。
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>
答案 0 :(得分:0)
<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>
尝试将列包装在scrollview的一侧,并将标题保留在scrollview
之外
答案 1 :(得分:0)
我发现了它的问题。显然,我应该将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>