2015-07-21 56 views
3

目前,我開發了一個android應用程序。在我的活動中,我想根據它們的大小放置我的元素。我解釋一下:我有3個的LinearLayout在GridLayout這樣的:如何根據其大小放置物品?

enter image description here

網格佈局(2,2,橫向)允許把LinearLayouts這樣的:

enter image description here

我想GridLayout(,,水平),但只是根據元素的大小。

例如,如果屏幕很大,可以將3 LinearLayout放在同一條線上,反之如果屏幕很小,則可以逐線LinearLayout。

我希望我已經清楚,在此先感謝。

+0

我想這樣的事情之前..但我使用噸的LinearLayout的,我只是用自己layout_weight玩.. – Sheychan

+0

你可以根據所需的大小使用不同的佈局xml文件(http://developer.android.com/guide/practices/screens_support.html)。如果LinearLayouts大小可能不同,則必須動態更改佈局佈局。 –

+0

可能的重複[如何在Android中做類似FlowLayout的事情?](http://stackoverflow.com/questions/4474237/how-can-i-do-something-like-a-flowlayout-in-android) –

回答

0

是的,當然你可以做。

您需要爲不同的密度設備創建不同的佈局目錄。

例如佈局LDPI佈局HDPI等。並定義所需的那種內這些佈局。

res/layout/my_layout.xml    // layout for normal screen size ("default") 
res/layout-small/my_layout.xml  // layout for small screen size 
res/layout-large/my_layout.xml  // layout for large screen size 
res/layout-xlarge/my_layout.xml  // layout for extra large screen size 
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation 

並且在不同的my_layout.xml文件中定義您需要的一個,兩個或三個linearlayouts。

+0

我認爲OP需要比這更動態的東西.... –

+0

@Orabîg是的,但我試圖給他的建議 – Nabin

相關問題