我正在嘗試用兩個單獨的圖形數據視圖編寫應用程序 - 一個是X-Y圖形。另一個是X vs T圖。我想要兩個垂直排列,X-Y圖形在上面。我寫了一個擴展到管理繪圖的View類,這不是問題。Android佈局異常 - 實際佈局不符合Android Studio外觀。
我最初使用的RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CCCCFF"
android:orientation="vertical"
android:gravity="center_horizontal">
<RelativeLayout
android:id="@+id/button_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="clearCanvas"
android:text="@string/btn1Text"
style="@android:style/Widget.Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="startPlot"
android:text="@string/btn2Text"
android:layout_toRightOf="@id/button1"
style="@android:style/Widget.Button" />
</RelativeLayout>
<co.android.bmd.chaoswithtime.CanvasView
android:id="@+id/plot_canvas"
android:layout_width="1000px"
android:layout_height="1000px"
android:textColor="#FFFFFF" />
<co.android.bmd.chaoswithtime.CanvasView
android:id="@+id/trend_canvas"
android:textColor="#FFFFFF"
tools:layout_below="@id/plot_canvas"
android:layout_height="500px"
android:layout_width="1000px" />
</RelativeLayout
根據Android Studio中所示的佈局,這應該得到所需的結果: XT視圖覆蓋在XY視圖:
我已經嘗試了許多變體來獲得對齊排列,但唯一的方法是爲XT視圖添加一個很大的頂部邊距 - 否非常滿意。
我可以使用LinearLayout得到我想要的,但無法弄清爲什麼Relativelayout不起作用(以及爲什麼Android Studio中的預覽與來自同一個包的模擬結果之間存在差異(仿真結果在實際設備上居然出現爲好。)
任何人都可以想出一個解釋?
爲什麼工具:layout_below而不是android:layout_below? – samgak
這就是我從AS中的佈局包得到的 - 它已經修復了繪圖順序。但現在這兩個圖形面板是左對齊的,而不是中央。 – user1815293
使用android:layout_centerHorizontal =「true」 – samgak