Ненужные отступы или поля в View [Android / Kotlin] - PullRequest
0 голосов
/ 23 ноября 2018

Я не знаю, где я ошибаюсь и где я ошибаюсь

Я фиксирую макет с помощью инспектора макетов

ФАЙЛ XML МОЕГО ВИДА

<?xml version="1.0" encoding="utf-8"?>
<package.MyView
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="wrap_content"
android:padding="10dp">

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    app:cardCornerRadius="6dp"

    android:background="#FFF"
    android:foregroundGravity="center"
    app:cardElevation="6dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text"
        android:gravity="center"
        android:inputType="textMultiLine"
        android:ems="10" android:padding="4dp"/>
</android.support.v7.widget.CardView>
</package.MyView>

MyView.kt

class MyView :RelativeLayout
{
    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()

        /*var Anim:Animation = AnimationUtils.loadAnimation(this.context,R.anim.card_flip_left_in)
        this.animation=animation
        animation.start()*/
       // this.setPadding(10,10,10,10)
                val animation = AnimationUtils.loadAnimation(this.context, R.anim.slide_right_in)
                animation.startOffset = 0
                this@MyView.startAnimation(animation)
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()

    }
}

slide_right_in.xml Файл анимации

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="2000"/>
</set>

Проблема: я не могу понять, почему добавляется поле или отступ сверху и снизу на фоне Cardview, когда фон получает Draw ....

Тестирование завершено: эмулятор и реальное устройство VivoV7 Plus

enter image description here

Проблема в том, что при просмотре карты появляются ненужные отступы или поля сверху и слева

enter image description here

Размер MyView, как и ожидалось ....

enter image description here

Размер CardView Как и ожидалосьно здесь фоновый рисунок в неправильном положении, как вы можете понять на изображении выше

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...