在边缘弄乱的布局背景

Raf*_*ima 9 android trim margin android-layout android-relativelayout

我正在尝试为我的视频播放器制作一个微调吧

trimmer_bar.xml

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/thumbsBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        tools:background="@color/trimmerBarSelected">


        <ImageView
            android:id="@+id/leftThumb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription=""
            android:scaleType="fitStart"
            android:src="@drawable/ic_left_thumb" />


        <ImageView
            android:id="@+id/rightThumb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:contentDescription=""
            android:scaleType="fitEnd"
            android:src="@drawable/ic_right_thumb" />


    </RelativeLayout>
    <ImageView
        android:id="@+id/progressIndicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="60dp"
        android:layout_marginTop="3dp"
        android:contentDescription=""
        android:scaleType="centerCrop"
        android:src="@android:drawable/btn_star_big_on" />

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

activity_video_viewer:

 <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#a8c71c"
        tools:context=".activities.VideoTrimmerActivity">

        <com.tomatedigital.instagram.longstories.ui.TrimmerBar
            android:id="@+id/trimmerBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/trimmerBarSelected"
            />
    </FrameLayout>
Run Code Online (Sandbox Code Playgroud)

它的逻辑运作得很好:当用户触摸时,我检测到它是否在左拇指上的任何拇指和外壳上我调整了thumbBar的左边距,右边的情况我调整右边距...

由于两个imageview与边缘对齐,这种行为使它们移动......但实际上移动的是整个RelativeLayout

问题是甚至调整边距并移动图像视图,相对布局仍然显示边缘区域中的背景

忽略整个计算我使用以下方法设置边距:

this.thumbsBar= (RelativeLayout) findViewById(R.id.thumbsBar);
this.thumbsBarLayout = (LayoutParams) this.thumbsBar.getLayoutParams();
this.thumbsBarLayout.leftMargin = this.leftMargin;
this.thumbsBarLayout.rightMargin = this.rightMargin;
this.thumbsBar.setLayoutParams(this.thumbsBarLayout);
Run Code Online (Sandbox Code Playgroud)

================================================== =============

更新:

使其更容易理解

我是这样的:

在此输入图像描述

我应该:

在此输入图像描述

Che*_*amp 2

com.tomatedigital.instagram.longstories.ui.TrimmerBar与您的RelativeLayout具有相同的背景,并且宽度为match_parent。您并没有真正指定如何加载布局,我假设它位于您的自定义视图中。

对于测试,更改自定义视图的背景颜色,看看您在边距中看到的背景是否来自relativelayout或自定义视图。我的猜测是它来自自定义视图,更改自定义视图中的背景颜色将解决您的问题。