2016-12-04 62 views
1

當滾動視圖作爲根標記包含在內時,不會顯示將屏幕精確分割爲兩個的行分隔符。否則,它的工作正常。線路分隔符不工作滾動視圖Android

這是我的佈局文件。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

    <LinearLayout 
     android:id="@+id/firstLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toLeftOf="@+id/secondView" 
     android:orientation="vertical" 
     android:paddingLeft="8dp"> 

     <TextView 
      android:id="@+id/Goals" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:layout_marginTop="15dp" 
      android:fontFamily="sans-serif-smallcaps" 
      android:text="Goals Scored- MANU" 
      android:textSize="18sp" /> 

     <Button 
      android:id="@+id/AddButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingTop="20dp" 
      android:text="+" /> 

     <Button 
      android:id="@+id/SubButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:text="-" /> 


     <TextView 
      android:id="@+id/Fouls" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:fontFamily="sans-serif-smallcaps" 
      android:text="Fouls" 
      android:textSize="18sp" /> 

     <Button 
      android:id="@+id/AddButton2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingTop="20dp" 
      android:text="+" /> 

     <Button 
      android:id="@+id/SubButton2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="-" /> 


     <TextView 
      android:id="@+id/goalsscoredteamone" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/foulsmadeteamone" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:textStyle="bold" /> 

    </LinearLayout> 

    <View 
     android:id="@+id/secondView" 
     android:layout_width="1dp" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" 
     android:background="#000000" /> 

    <LinearLayout 
     android:id="@+id/thirdLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_toRightOf="@+id/secondView" 
     android:orientation="vertical" 
     android:paddingLeft="8dp"> 

     <TextView 
      android:id="@+id/Goalsteam2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:layout_marginTop="15dp" 
      android:fontFamily="sans-serif-smallcaps" 
      android:text="Goals Scored MANC" 
      android:textSize="18sp" /> 

     <Button 
      android:id="@+id/AddButton3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingTop="20dp" 
      android:text="+" /> 

     <Button 
      android:id="@+id/SubButton3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:text="-" /> 

     <TextView 
      android:id="@+id/Foulsteam2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:fontFamily="sans-serif-smallcaps" 
      android:text="Fouls" 
      android:textSize="18sp" /> 

     <Button 
      android:id="@+id/AddButton4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingTop="20dp" 
      android:text="+" /> 
     <Button 
      android:id="@+id/SubButton4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="-" /> 
     <TextView 
      android:id="@+id/goalsscoredteamtwo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:textStyle="bold" /> 
     <TextView 
      android:id="@+id/foulsmadeteamtwo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" 
      android:textStyle="bold" /> 
    </LinearLayout> 
</RelativeLayout> 

各地需要的任何工作或任何可能的解決方案?

+0

發表您的完整的XML我們沒有法力這裏 –

+0

我只是問,因爲滾動視圖這背後的邏輯將高度作爲一個變量,而不是固定的高度,這使得故障線路分隔符 –

+0

所以我們需要假設你已經完成了所有的事情並解釋了邏輯......如果你認爲你已經做了正確的事情,爲什麼你要提出問題?再等一個小時,你就不會得到答案,如果你這樣做:D –

回答

1

這裏去答案 加android:fillViewport="true"到你的ScrollView它會工作!

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <ScrollView 
     android:fillViewport="true" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true"> 
      <LinearLayout 
       android:id="@+id/firstLayout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_toLeftOf="@+id/secondView" 
       android:orientation="vertical" 
       android:paddingLeft="8dp"> 

       <TextView 
        android:id="@+id/Goals" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dp" 
        android:layout_marginTop="15dp" 
        android:fontFamily="sans-serif-smallcaps" 
        android:text="Goals Scored- MANU" 
        android:textSize="18sp" /> 

       <Button 
        android:id="@+id/AddButton1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingTop="20dp" 
        android:text="+" /> 

       <Button 
        android:id="@+id/SubButton1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dp" 
        android:text="-" /> 


       <TextView 
        android:id="@+id/Fouls" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dp" 
        android:fontFamily="sans-serif-smallcaps" 
        android:text="Fouls" 
        android:textSize="18sp" /> 

       <Button 
        android:id="@+id/AddButton2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingTop="20dp" 
        android:text="+" /> 

       <Button 
        android:id="@+id/SubButton2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="-" /> 


       <TextView 
        android:id="@+id/goalsscoredteamone" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="20dp" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/foulsmadeteamone" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="20dp" 
        android:textStyle="bold" /> 

      </LinearLayout> 

      <View 
       android:id="@+id/secondView" 
       android:layout_width="1dp" 
       android:layout_height="match_parent" 
       android:layout_centerHorizontal="true" 
       android:background="#000000" /> 

      <LinearLayout 
       android:id="@+id/thirdLayout" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_toRightOf="@+id/secondView" 
       android:orientation="vertical" 
       android:paddingLeft="8dp"> 

       <TextView 
        android:id="@+id/Goalsteam2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dp" 
        android:layout_marginTop="15dp" 
        android:fontFamily="sans-serif-smallcaps" 
        android:text="Goals Scored MANC" 
        android:textSize="18sp" /> 

       <Button 
        android:id="@+id/AddButton3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingTop="20dp" 
        android:text="+" /> 

       <Button 
        android:id="@+id/SubButton3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dp" 
        android:text="-" /> 

       <TextView 
        android:id="@+id/Foulsteam2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="20dp" 
        android:fontFamily="sans-serif-smallcaps" 
        android:text="Fouls" 
        android:textSize="18sp" /> 

       <Button 
        android:id="@+id/AddButton4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:paddingTop="20dp" 
        android:text="+" /> 
       <Button 
        android:id="@+id/SubButton4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="-" /> 
       <TextView 
        android:id="@+id/goalsscoredteamtwo" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="20dp" 
        android:textStyle="bold" /> 
       <TextView 
        android:id="@+id/foulsmadeteamtwo" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="20dp" 
        android:textStyle="bold" /> 
      </LinearLayout> 
     </RelativeLayout> 


    </ScrollView> 



</RelativeLayout> 
+0

它完美的作品! –

+1

這裏是我複製xoxo的邏輯「記住android:layout_height =」fill_parent「的意思是」將高度設置爲父級的高度「。這顯然不是你在使用ScrollView時想要的。畢竟,ScrollView會如果它的內容總是和自身一樣高,要解決這個問題,你需要使用名爲android:fillViewport的ScrollView屬性,當設置爲true時,這個屬性會導致滾動視圖的子節點擴展到ScrollView的高度if當孩子比ScrollView高時,屬性不起作用。「 –

+0

明白了。在縱向模式下工作得很好。在橫向模式中,我觀察到行分隔符丟失。但其他行爲沒有問題。任何想法? –