【问题标题】:Fill Parent on Horizontal List Row with Margin用边距填充水平列表行上的父级
【发布时间】:2013-02-08 18:39:38
【问题描述】:

好的,所以我在 ListView 上有一个水平相对布局,我想要 ListView 上不同行之间的边距,但我有一个问题。我有一个按钮被推到最右边,我希望点击区域尽可能大。如果相对布局的根元素上没有边距,我会很好,我的按钮将占据行的整个高度。但问题是因为有边距,所以用户有机会点击按钮上方和下方的边距来触发 OnItemClick 事件,这不是按钮的预期功能,有时可能会令人沮丧。

例子:

<RelativeLayout android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:orientation="horizontal"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="5dp">

 <ImageButton
        android:id="@+id/list_button"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/btn"
        android:background="@android:drawable/list_selector_background" />
</RelativeLayout>

任何帮助将不胜感激,显然它可能我只是看不到它。

【问题讨论】:

    标签: android listview margin android-relativelayout imagebutton


    【解决方案1】:

    解决此问题的一种方法是将 ImageButton 包装在一个透明的布局视图中(相对、线性、框架 - 取决于您的需要),确实占据了整个空间(即 android:layout_width 和 android: layout_height 是 fill_parent)。然后将与按钮相同的单击处理程序添加到外部布局。

    【讨论】:

    • 我在我的应用程序中做到了。注意match_parent 更好,fill_parent 已弃用。
    • 所以我在 RelativeLayout 内嵌套了一个 FrameLayout 并使用 alignParentRight 将其推到右侧,但它仍然没有填满整个高度。同样,我可能应该提到我的文件的实际布局是 顶部 LinearLayout 的宽度和高度都是 match_parent。
    猜你喜欢
    • 1970-01-01
    • 2011-05-14
    • 2017-03-10
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多