0

我创建了具有标题和滚动正文的布局。我可以在纵向模式下看到标题,但是当它进入横向模式或者我不得不滚动它时,标题丢失了。横向/滚动视图中的视图缺失

我希望头部保持静止,只有身体应该滚动。 左侧为纵向,右侧为横向。

sample image

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

你 “header_inspection_view” 这里没有显示。对? – Ankita

+0

@Ankita是的,我的'header_inspection'视图在横向时丢失。如果我将标题添加到主活动中,则标题将随着它一起滚动。我希望标题保持静态 – xxmilcutexx

+0

尝试将scrollview放入线性布局中,并为dimesion(高度和宽度)设置match_parent属性。 – Ankita

回答

0

以外我发现这个问题吧。显然我应该包括layout_heightlayout_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> 
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>

尝试包裹列侧滚动视图,并保持头滚动视图