2013-10-05 31 views
-1

我在1个活动中有2个单独的自定义视图。 我有2个问题:在1个活动中显示2个单独的自定义视图android

1-我该怎么做(把2视图并排)?

2-我怎样才能把第二个视图在显示器的后半部分它意味着如何让视图考虑(宽度/ 2,0)而不是(0,0)来启动? 注意:我的视图的高度是显示的高度,我的视图的宽度是显示宽度的宽度/ 2。

我设置onMeasure()方法是这样

@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    int measuredWidth = widthMeasureSpec/2; 
    int measuredHeight = heightMeasureSpec; 
    setMeasuredDimension(measuredWidth,measuredHeight); 
} 

display

回答

2

尝试添加LinearLayout水平导向,内外两个视图与weight=1。它看起来像.-

<LinearLayout 
    android:width="match_parent" 
    android:height="wrap_content" 
    android:orientation="horizontal"> 

    <YourCustomView1 
     android:width="wrap_content" 
     android:height="wrap_content" 
     android:weight="1" /> 

    <YourCustomView2 
     android:width="wrap_content" 
     android:height="wrap_content" 
     android:weight="1" /> 

</LinearLayout> 
相关问题