2012-05-16 34 views
0

下午好,ListView中的RelativeLayout

我無法讓一個RelativeLayout在ListView中工作。如果我將佈局更改爲線性等,我會看到它的行爲與我所期望的相同,但RelativeLayout正在將所有內容都重疊到重疊的空間中。現在我的未受教育的猜測是,它試圖將所有東西塞進行列。我認爲它會擴大這一行,但可能不會或不是這個問題。

請注意我的代碼已縮寫爲空格。

反正在我父XML:

<LinearLayout ..._width="fill_parent" ..._height="fill_parent" ...orientation="vertical" > 
    <ListView ...layout_width="fill_parent" ...layout_height="fill_parent" /> 
</LinearLayout> 

所以我的想法是,這將填補設備屏幕,並在Eclipse的GraphicalLayout觀點看來,它確實。

爲ListView我的「行」的定義是這樣的:

<RelativeLayout width="fill_parent" height="fill_parent" > 

    <ImageView 
     android:layout_width="60dp" 
     android:layout_height="30dp" 
     android:layout_alignParentLeft="true" 
     android:layout_marginTop="15dp" 
     android:layout_marginLeft="5dp" /> 
     ..... 
</RelativeLayout> 

如前所述我認爲這將填補所有可用空間,但它似乎只是填補某種「默認」行高?

不知道我缺少什麼,但任何幫助將不勝感激。

+0

看到這個TUTS http://samir-mangroliya.blogspot.in/p/android-customized-listview.html –

回答

0

我結束了重寫一個ArrayAdapter的getView,然後設置的高度和寬度,以動態確定的畫面尺寸

...剪斷....

int[] iarry_ScrnDim = new int[2]; 

DisplayMetrics metrics = new DisplayMetrics(); 
metrics = ctx_Currnt.getResources().getDisplayMetrics(); 

iarry_ScrnDim[0] = metrics.heightPixels; 
iarry_ScrnDim[1] = metrics.widthPixels; 

return iarry_ScrnDim; 

....剪斷....

if (vw_BigRow == null) 
{ 
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    vw_BigRow = inflater.inflate(R.layout.liftdatalayout, null); 
} 

vw_BigRow.setMinimumHeight(mHeight); 
vw_BigRow.setMinimumWidth(mWidth); 
2

在您的xml中使用佈局屬性layout-above,layout-below,layout-toRightOf,layout-toLeftOf。這樣的項目將被放在你想要他們去的地方。現在你正在根據父母設置所有內容,因此它們都將重疊

+0

OHHH不要覺得愚蠢。是的,就是這樣。 – GPGVM

+0

我想我沒有想到。我將layout_alignParentBottom =「true」和layout_alignParentRight =「true」添加到了一個應該在底部但不是的元素。仍然像擠在一排一樣擠在一起。如果我將ListView「row」XML RelativeLayout設置爲500dp的minheight,則所有內容都會展開,因此我又回到了認爲列表視圖存在某種默認行的約束條件。 – GPGVM

1

RelativeLayout默認情況下,它將其錨定到佈局的左上角。

使用的RelativeLayout的非常方便的屬性,你可以安排孩子們都

  • 相對於彼此,並
  • 相對父視圖。

layout_alignParentLeft..Right..Top..Bottomlayout_centerInParentlayout_centerHorizontallayout_centerVerticallayout_toLeftOf..toRightOf..above..below

這些屬性將幫助你在一個非常有效的(平)路所需的顯示,所以我建議繼續閱讀它,並考慮使用它來代替其他佈局容器來顯示覆雜的視圖。

相關問題