为什么如果作为的ListView行视图LinearLayout中的保证金被忽略 [英] Why LinearLayout's margin is being ignored if used as ListView row view

查看:97
本文介绍了为什么如果作为的ListView行视图LinearLayout中的保证金被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在想,如果我仅仅提供了的LinearLayout 单层作为ListView的行认为,其利润率将被忽略。

I was wondering, if I merely provide a single layer of LinearLayout as ListView's row view, its margin will be ignored.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="5dp"

不过,如果我提供的LinearLayout 的双电层,与第一层充当虚拟层,它的利润率将是不容忽视的。

However, if I provide double layer of LinearLayout, with first layer acted as "dummy" layer, its margin will not be ignored.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/buyPortfolioLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"

我想知道为什么会发生这样?

May I know why it happen so?

推荐答案

事实是,的保证金的LinearLayout (孩子)要求其父布局(容器),以给孩子布置的x值幅度。

The fact is that, the margin of LinearLayout (child) asks its parent layout (container) to give child layout a margin of x value.

因此​​,如果父布局的LayoutParams支持的利润率则该保证金荣幸和应用。

So if the parent layouts' LayoutParams support the margins then that margin is honored and applied.

的ListView 使用<一个href="http://developer.android.com/reference/android/widget/AbsListView.LayoutParams.html"><$c$c>AbsListView.LayoutParams在默认情况下,它不包含任何保证金的支持,只是高度和宽度,这就是为什么,它只是忽略了利润率PARAMS值。

ListView uses AbsListView.LayoutParams by default, which doesn't include any margin support, just the height and width, thats why, it simply ignores the params value for margins.

而其他布局PARAMS像<一个href="http://developer.android.com/reference/android/app/ActionBar.LayoutParams.html"><$c$c>ActionBar.LayoutParams, <一href="http://developer.android.com/reference/android/widget/FrameLayout.LayoutParams.html"><$c$c>FrameLayout.LayoutParams, <一href="http://developer.android.com/reference/android/widget/GridLayout.LayoutParams.html"><$c$c>GridLayout.LayoutParams, <一href="http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html"><$c$c>LinearLayout.LayoutParams和<一href="http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html"><$c$c>RelativeLayout.LayoutParams是的<一个孩子href="http://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html">ViewGroup.MarginLayoutParams,该荣誉的孩子的边距值。

Whereas other layout params like ActionBar.LayoutParams, FrameLayout.LayoutParams, GridLayout.LayoutParams, LinearLayout.LayoutParams and RelativeLayout.LayoutParams are child of ViewGroup.MarginLayoutParams, which honors the child's margin values.

这篇关于为什么如果作为的ListView行视图LinearLayout中的保证金被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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