Android 添加了不填充宽度的视图

Android 添加了不填充宽度的视图,android,android-layout,android-relativelayout,Android,Android Layout,Android Relativelayout,首先,我只能提供有限的代码,因为这是为了工作。有了这个 我正在以编程方式添加视图。高度完美。父视图上没有填充,添加的视图上没有边距,但左侧有一个8dp到12dp的填充/边距/间隙,我想不出来。我真的需要这个视图来扩展父视图的整个宽度。非常感谢您的帮助 父布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/a

首先,我只能提供有限的代码,因为这是为了工作。有了这个

我正在以编程方式添加视图。高度完美。父视图上没有填充,添加的视图上没有边距,但左侧有一个8dp到12dp的填充/边距/间隙,我想不出来。我真的需要这个视图来扩展父视图的整个宽度。非常感谢您的帮助

父布局:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/baseLayoutRootParent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
结果如下:


首先删除添加布局中每个元素上的
marginLeft
/
margintart
,然后查看它是哪一个


这个问题有点不清楚,因为很难在图片和给定布局之间建立联系。
viewCheckBox
在哪里,
viewImage
在哪里等等。

您至少可以告诉我们它是xml中的哪个元素吗?我包括了根视图的xml和我要添加的视图的xml。我想让子视图填满根的整个宽度,但不是这样。这篇文章应该是-1吗?我正在添加整个子视图,我可以理解。我将删除所有边距和填充,并在几分钟后报告回刚才意外删除的这一行:view.setX(viewLocation[0]);现在它完全扩展了。
<?xml version="1.0" encoding="utf-8"?>
<ImageView
    android:id="@+id/viewImage"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:layout_centerVertical="true"
    android:padding="2dp" />

<LinearLayout
    android:id="@+id/textHolder"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
    android:layout_toEndOf="@+id/viewImage"
    android:layout_toRightOf="@+id/viewImage"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_padding"
    android:paddingEnd="@dimen/activity_horizontal_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingStart="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_padding">

    <TextView
        android:id="@+id/viewText"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        app:fontName="fonts/lato_regular.ttf" />

</LinearLayout>

<CheckBox
    android:id="@+id/viewCheckBox"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:clickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:paddingBottom="@dimen/activity_vertical_padding"
    android:paddingEnd="@dimen/activity_horizontal_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingStart="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_padding"
    android:visibility="gone" />

<LinearLayout
    android:id="@+id/lineDivider"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:background="@android:color/darker_gray"
    android:orientation="horizontal" />
    LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.child_view, rootParent, false);
    view.setBackgroundColor(getResources().getColor(R.color.blue));

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, viewHeight);
    lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
        lp.addRule(RelativeLayout.ALIGN_PARENT_START, RelativeLayout.TRUE);

    view.setLayoutParams(lp);
    view.setId(R.id.viewID);

    ImageView iv = (ImageView) view.findViewById(R.id.viewImage);
    Picasso.with(Activity.this).load(file.image).placeholder(R.drawable.ic_launcher).transform(new CircleTransform()).into(iv);

    TextView tv = (TextView) view.findViewById(R.id.viewText);
    tv.setText(file.name());
    tv.setTextColor(getResources().getColor(android.R.color.white));

    (rootParent).addView(view);

    // these are set from another activity.  It's the x/y coordinates of a view that this view copies
    view.setX(viewLocation[0]);
    view.setY(viewLocation[1] + (findViewById(R.id.toolbar)).getHeight());