2011-09-17 63 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