Android ListView中的RelativeLayout

Android ListView中的RelativeLayout,android,Android,下午好 我很难让RelativeLayout在ListView中工作。如果我将布局更改为线性等,我会看到它的行为与我预期的一样,但相对的布局将所有内容都压缩到重叠的空间中。现在我未受过教育的猜测是,它试图把所有东西塞进一排。我原以为这会扩大这一争议,但也许不会,或者这不是问题所在 请注意,我的代码已缩写为空格 无论如何,在我的父XML中: <LinearLayout ..._width="fill_parent" ..._height="fill_parent" ...orientatio

下午好

我很难让RelativeLayout在ListView中工作。如果我将布局更改为线性等,我会看到它的行为与我预期的一样,但相对的布局将所有内容都压缩到重叠的空间中。现在我未受过教育的猜测是,它试图把所有东西塞进一排。我原以为这会扩大这一争议,但也许不会,或者这不是问题所在

请注意,我的代码已缩写为空格

无论如何,在我的父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>

.....
如前所述,我认为这将填充所有可用空间,但它似乎只填充某种“默认”行高度


不确定我缺少了什么,但如果有任何帮助,我将不胜感激。

在xml中使用布局属性
上面的布局
下面的布局
布局tolightof
布局toLeftOf
。这样,物品就会放在你想要的地方旁边。现在,您正在根据父级设置所有内容,以便它们都将重叠使用xml中的布局属性
上面的布局
下面的布局
布局toRightOf
布局toLeftOf
。这样,物品就会放在你想要的地方旁边。现在,您正在根据父项设置所有内容,以便它们都将重叠。默认情况下,将其子项锚定到布局的左上角

通过使用非常方便的
RelativeLayout
属性,您可以同时安排子项

  • 相对而言,以及
  • 相对于父视图
layout\u alignParentLeft
Right
Top
Bottom
layout\u centerInParent
layout\u centerlevertical
layout\u-toLeftOf
.toRightOf
、上方
、下方


这些属性将帮助您以非常有效的(平坦的)方式获得所需的显示,因此我建议继续阅读它,并考虑使用它代替复杂视图的其他布局容器。默认情况下,

<代码> RealValayOut< <代码>将其子锚定在布局的左上角。 通过使用非常方便的
RelativeLayout
属性,您可以同时安排子项

  • 相对而言,以及
  • 相对于父视图
layout\u alignParentLeft
Right
Top
Bottom
layout\u centerInParent
layout\u centerlevertical
layout\u-toLeftOf
.toRightOf
、上方
、下方


这些属性将帮助您以非常高效(平坦)的方式获得所需的显示,因此我建议继续阅读它,并考虑使用它代替复杂视图的其他布局容器。

< P>我结束了对AARAYAdvor的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);
……剪断

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);

我最终覆盖了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);
……剪断

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);

看这个啧啧,看这个啧啧,哦,我不觉得自己很笨。是的,就是这样。我想我还没弄明白。我将layout\u alignParentBottom=“true”和layout\u alignParentRight=“true”添加到一个元素中,该元素应该在底部,而不是底部。还是挤在一起,好像要挤成一排。如果我将ListView“row”XML RelativeLayout设置为最小高度500dp,那么所有内容都会展开,因此我会重新考虑ListView有某种默认的行限制。哦,我不觉得自己很笨。是的,就是这样。我想我还没弄明白。我将layout\u alignParentBottom=“true”和layout\u alignParentRight=“true”添加到一个元素中,该元素应该在底部,而不是底部。还是挤在一起,好像要挤成一排。如果我将ListView“row”XML RelativeLayout设置为最小高度500dp,那么所有内容都会展开,因此我又回到了对ListView有某种默认行限制的想法。