我最近問了一個關於如何在視圖頂部添加視圖的問題,之後詢問我意識到我需要在繼續進一步之前向我的應用添加更好的佈局。我的Android佈局應該是什麼樣子?
我在讀Android Layout Tricks,但注意到它專門用於文本視圖和圖像視圖。我正在尋找與兩個自定義視圖。所以我決定在油漆上畫一個快速圖像,希望更清楚地表明我想要做的事情。
這是我多麼希望我的佈局分割的意見。 :
這是它會如何看待與得出的意見。顯然,紫色和藍色邊界將是背景顏色(灰色)。上面的數據只是顯示用相應顏色繪製的圖的y軸截距。 (所以有將是對彼此頂部繪製多個圖形視圖)
所以我的問題是,會是什麼我的主要內容視圖是什麼樣子?我認爲它會有一個線性佈局,但我對這些佈局頗爲陌生。
編輯
使用TextViews我能拿出類似的東西使用下面的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Data Placeholder"
android:background="#733674"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"/>
<TextView
android:text="Graph Placeholder"
android:background="#374F82"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="80"/>
</LinearLayout>
</LinearLayout>
因此,其實仍然是唯一的問題是,我應該使用TextViews ?在我的活動意義是我能夠添加我的自定義視圖這些TextViews是哪裏?或者我應該將自定義視圖添加到XML中?
即,
<DataView
android:text="Data Placeholder"
android:background="#733674"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"/>
<GraphView
android:text="Graph Placeholder"
android:background="#374F82"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="80"/>
我的自定義視圖是用Java編寫的,我不知道如何讓佈局知道視圖的位置,如果我這樣做。
您是否在尋找XML代碼或...? –
@Michell Bak正確,我在尋找Xml這個:)我想我應該澄清一點。 – StartingGroovy
不完全確定您對自定義數據和圖形視圖的期望,但如果您只是尋找代碼來拆分兩個視圖(大約30/70,如圖所示),則可以使用垂直LinearLayout中的layout_weight參數。 –