Android的布局围绕在RelativeLayout的自定义的ListView [英] Android layout centering in RelativeLayout for custom ListView

查看:148
本文介绍了Android的布局围绕在RelativeLayout的自定义的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很拉我的头发在这一个。一些背景知识。我有全都有复选框旁边的项目列表。如果取消选中复选框,出现一个按钮,使您可以从列表中删除的项目。这种倒退似乎在第一,但我们只希望选择的项目,才有资格进行进一步的处理,等等。这是我的布局:

I'm really pulling my hair out over this one. Some background. I have a list of items that all have checkboxes next to them. When you deselect a checkbox, a button appears that allows you to delete the item from the list. This seems backwards at first but we only want "selected" items to be eligible for further processing, etc. This is my layout:

<RelativeLayout android:id="@+id/rlBlahBlah" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:minHeight="?android:attr/listPreferredItemHeight"
                xmlns:android="http://schemas.android.com/apk/res/android">
  <CheckBox android:text="" 
            android:id="@+id/cbDeleteItem" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:focusable="false"
            />
  <TextView android:text="" 
            android:id="@+id/tvItemText" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:textSize="14dip"
            android:paddingLeft="3dip"
            android:paddingRight="3dip"
            android:paddingTop="13dip"
            android:gravity="fill_vertical"
            android:layout_toRightOf="@id/cbDeleteItem"
            />
  <Button android:layout_height="wrap_content" 
          android:id="@+id/btnDelete" 
          android:text="Delete" 
          android:layout_width="wrap_content"
          android:layout_alignParentRight="true"
          android:gravity="center_vertical"
          android:focusable="false"
          />
</RelativeLayout>

我不能得到的3个项目在我行救我一命垂直居中。 layout_gravity 重力 layout_centerVertical ,没有它的工作原理。我敢肯定,我的问题是,一些微小的设置翻页的地方,但我真的在这个束手无策。

I cannot get the 3 items to center vertically in my row to save my life. layout_gravity, gravity, layout_centerVertical, none of it works. I'm sure my issue is some tiny setting to flip somewhere, but I'm really at wits end on this.

编辑:我知道TextView的是fill_vertical,这是一些随机的东西,我试图

edit: I know the textview is "fill_vertical", that's some random stuff I was trying.

推荐答案

您的问题可能不是由于布局,但你是如何膨胀的布局。事实上,它甚至可能是我的错,这取决于你在哪里学到的技术......

Your problem is probably not due to the layout, but how you are inflating the layout. In fact, it might even be my fault, depending on where you learned your technique...

要引用全方位present <一href="http://groups.google.com/group/android-developers/browse%5Fthread/thread/6a97422a8b0faf34">Romain盖伊:

To quote the omnipresent Romain Guy:

充气的正确使用()   适配器是:

the correct usage of inflate() in adapters is:

膨胀(layoutId,父母,假);

inflate(layoutId, parent, false);

传递父(给你们一个   在getView())参数允许用户界面   工具包创建适当的   的LayoutParams对象。传递假   告诉工具包不要拨打   parent.addView(theInflateChild)时,由于   ListView控件将在后面做了自己的魔力   上。

Passing the parent (given to you as a parameter in getView()) allows the UI toolkit to create the appropriate LayoutParams object. Passing false tells the toolkit to NOT call parent.addView(theInflateChild), since ListView will do its own magic later on.

如果您使用膨胀(layoutId,空),因为我历来建议,生活还算可以,除非你试图使用 RelativeLayout的作为行的基地布局,并尝试使用垂直居中。

If you use inflate(layoutId, null), as I have traditionally advised, life is OK unless you try using RelativeLayout as the base layout of the rows and try to use vertical centering.

我会更新我的书,这样的反映在未来几周内的新建议。

I will be updating my books and such to reflect the new advice in the coming weeks.

这篇关于Android的布局围绕在RelativeLayout的自定义的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆