2017-02-28 121 views
0

當我的佈局添加scrollview時,我面臨一個問題。當我將方向改爲橫向並滾動時,視圖似乎重疊Portrait viewLandscape viewMPAndroidChart折線圖scrollview重疊

以下是佈局文件中的代碼。任何一個人都可以幫我弄清楚爲什麼細節和圖表過度分開?

<?xml version="1.0" encoding="utf-8"?> 

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

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin"> 

     <com.github.mikephil.charting.charts.LineChart 
      android:id="@+id/line_chart" 
      android:layout_width="match_parent" 
      android:layout_height="300dp"></com.github.mikephil.charting.charts.LineChart> 


     <android.support.v7.widget.GridLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:columnCount="2"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/symbol" 
       android:text="@string/detail_symbol" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/symbolValue" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text="IBM" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/price" 
       android:text="@string/price" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/priceValue" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text="Price" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/percentage_change" 
       android:text="@string/percentage_change" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text="Percentage change" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/percentageChangeValue" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text=".09%" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/absolute_change" 
       android:text="@string/absolute_change" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/absolutechangeValue" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text="5.5" /> 

     </android.support.v7.widget.GridLayout> 

    </LinearLayout> 
</ScrollView> 

回答

0

試試這個

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin"> 

     <com.github.mikephil.charting.charts.LineChart 
      android:id="@+id/line_chart" 
      android:layout_width="match_parent" 
      android:layout_height="300dp"></com.github.mikephil.charting.charts.LineChart> 


     <android.support.v7.widget.GridLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:columnCount="2"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/symbol" 
       android:text="@string/detail_symbol" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/symbolValue" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text="IBM" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/price" 
       android:text="@string/price" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/priceValue" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text="Price" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/percentage_change" 
       android:text="@string/percentage_change" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text="Percentage change" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/percentageChangeValue" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text=".09%" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/absolute_change" 
       android:text="@string/absolute_change" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/absolutechangeValue" 
       app:layout_columnWeight="1" 
       app:layout_rowWeight="1" 
       tools:text="5.5" /> 

     </android.support.v7.widget.GridLayout> 

    </LinearLayout> 
</ScrollView> 
+0

不幸的是,這是行不通的。我在代碼中看不到太多差異 – Spindoctor

+0

在LinearLayout中檢查:android:layout_width =「match_parent」 android:layout_height =「match_parent」 –