2015-10-04 58 views
1

我有使用RelativeLayout顯示內容的片段活動。我正在顯示文字,一切正常。如何在片段上使用onDraw?

現在我想添加一些圖形信息,我有問題。 Fragment中沒有onDraw()方法。

有沒有一種方法可以使用RelativeLayout來顯示文本信息並同時在Fragment上繪製?

謝謝。

更新:

我使用這個代碼:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{ 
    mFragmentView = inflater.inflate(R.layout.fragment_stat, container, false); 
    return mFragmentView; 
} 

據我瞭解,我將不得不重寫(或改變)由Inflater.inflate創建的視圖()方法。我怎樣才能做到這一點?

+0

我認爲構建自定義相對佈局和重寫onDraw是一種方法。 – subhash

+0

[在Android中的碎片中繪圖]可能的重複(http://stackoverflow.com/questions/23280685/drawing-in-a-fragment-in-android) – user2413972

回答

1

你只是不明白是什麼片段。這是一個常見問題。瞭解official documentation

該片段就像是活動的一小部分。它沒有繪畫的方法。繪圖有視圖。你只需要添加你的視圖到一個片段。

Here's an example