1
我尝试将PlotView
(自定义视图)添加到LinearLayout
中。我的LinearLayout
的weightSum
有8个。在我的.xml里面,我定义了一个Space
(3的权重),它必须出现在我的PlotView
和Button
(权重为1)之上,应该跟随我的情节。到现在为止还挺好。 现在PlotView
以编程方式添加,权重为4.但是,它总是会消耗几乎整个屏幕,并且我不确定我在这里做错了什么。布局中的加权视图
我的代码:
main_activity.xml(片段)
<LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_alignParentEnd="true" android:id="@+id/linlayout" android:weightSum="8"> <Space android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_weight="3"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/calibrate" android:id="@+id/calibration" android:layout_weight="1" android:layout_gravity="center_horizontal" /> </LinearLayout>
main_activity.java(片段)
LinearLayout layout = (LinearLayout) findViewById(R.id.linlayout); plotView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 4f)); layout.addView(plotView, 1);
任何想法我做错了什么?