2016-12-12 42 views
0

我似乎無法將按鈕和androidplot一起放入滾動視圖中,以便我可以向下滾動,通過androidplot查看按鈕。我正在使用androidplot 0.9.8。將按鈕和androidplot添加到滾動視圖

這裏是我的xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:ap="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="example.example.MainActivity"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/plotLayout"> 
      <com.androidplot.xy.XYPlot 
        android:id="@+id/plot" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        ap:Label="test" 
        ap:domainLabel="test" 
        ap:rangeLabel="test" 
        ap:renderMode="use_main_thread"/> 
      <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" 
        android:layout_below="@id/plot"> 
        <Button 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:text="test"/> 
        <Button 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         android:layout_weight="1" 
         android:text="test"/> 
        </LinearLayout> 
     </RelativeLayout> 
</ScrollView> 

編輯:看來然而,當我指定了一定的高度爲androidplot(如機器人:layout_height =的 「600dp的」,而不是機器人:layout_height = 「match_parent」)它滾動罰款。爲什麼使用match_parent阻止它滾動?

+0

你RelativeView沒有正確關閉 –

+0

對不起,錯字。仍然得到相同的問題 –

回答

0

我設法通過以編程方式將手動大小設置爲圖來破解它。您可以獲取繪圖的佈局參數,然後手動更改高度。我認爲這似乎與高度有關?

XYPlot plot = (XYPlot) findViewById(R.id.plot); 
LayoutParams lp = plot.getLayoutParams(); 
lp.height = 1710; // You can set it to whatever height you require it to be, 1710 is just an example 
plot.setLayoutParams(lp); 
1

看起來你正在使用的match_parent一個值,你的情節,一個ScrollView因爲這兩種觀點的內部使用時,它創建了一個雞和蛋的情況高度依賴於對方告訴它什麼它的大小將是。

這裏要做的最好的事情是爲您的佈局xml中的情節提供一個明確的高度。如果這不是你的選擇,加入:

android:fillViewport="true" 

你的scrollview的XML也可以做的伎倆。 (通常有效,但我在各種情況下都聽到相反的報道)This blog post在基本問題上會有更多細節。

+0

我已經添加了android:fillViewport =「true」沒有效果(如原始帖子中所見)。我試圖將劇情高度設置爲Android屏幕的大小,這意味着我無法在xml中明確地聲明它。似乎以編程方式執行它可能是現在最好的選擇。謝謝你 –

相關問題