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);
任何想法我做錯了什麼?