2011-09-17 76 views
1

你好我已經發布了我的iPhone應用程序微距,並且現在將它移植到android。我不知道如何在滾動視圖中繪製線條,並且想知道我做錯了什麼。安卓在水平滾動視圖上繪製線條

這裏是我的滾動視圖界面的一部分

<HorizontalScrollView android:id="@+id/scroll_view" android:layout_above="@+id/btn_info" android:layout_alignParentTop="true" android:layout_height="match_parent" android:layout_width="match_parent" android:overScrollMode="always" android:layout_alignParentRight="true" android:layout_alignParentLeft="true"> 
      <LinearLayout android:layout_height="match_parent" android:id="@+id/scroll_layout" android:layout_width="match_parent"> 
      </LinearLayout> 
     </HorizontalScrollView> 

這是我plot_view類

public class PlotView extends View 
{ 
    Paint paint = new Paint(); 

    public PlotView(Context context) 
    { 
     super(context); 
     paint.setColor(Color.RED); 
    } 

    @Override 
    public void onDraw(Canvas canvas) { 
      canvas.drawLine(0, 0, 200, 200, paint); 
      canvas.drawLine(20, 0, 0, 20, paint); 
    } 
} 

,這是我的主要活動課的段

HorizontalScrollView scroll_view; 
LinearLayout scroll_layout; 
PlotView plot_view; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    scroll_view= (HorizontalScrollView)findViewById(R.id.scroll_view); 
    scroll_layout= (LinearLayout)findViewById(R.id.scroll_layout); 

    plot_view = new PlotView(this); 
    plot_view.setBackgroundColor(Color.WHITE); 
    scroll_layout.addView(plot_view); 
} 

plotview甚至沒有出現在滾動視圖上

如果可能的話,請看看我的iphone版本的應用程序免費。我要做的是在滾動視圖上繪製聲音。這樣你可以更好地瞭解我正在嘗試做什麼。

回答

0

您的PlotView尺寸爲零,您需要執行onMeasure(int, int)以確定其所需的尺寸,如解釋here所述。

您可能還需要爲其設置一些LinearLayout.LayoutParams,因爲您要通過代碼將視圖添加到LinearLayout

+0

我檢出了這個鏈接http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/LabelView.html我不得不復制onMeasure方法及其需求謝謝Zharf – Daniel