如何使线性布局的动画看起来可扩展
How to make the animation of the linearlayout look expandble
我有一个按钮,单击 linearlayout.The 按钮后我使布局可见。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="700"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
再次点击时,我添加反方向的动画。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="false"
android:shareInterpolator="false">
<translate
android:duration="700"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="100%"
android:toYDelta="0%" />
</set>
我的流程 运行 很顺利,但是线性布局来自屏幕的 x 100 并从 x 消失 100.But 我想要的是按钮不会出现在其 size.For 之外,我如何编辑它,就好像它正在进入只有动画的按钮,而不创建可扩展布局?
<LinearLayout
android:id="@+id/marinasSearchLinear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="2dp"
android:animateLayoutChanges="false"
android:background="@drawable/pin_back"
android:orientation="vertical"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:translationZ="5dp"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@+id/marinasSearchBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.SearchView
android:id="@+id/marinasSearchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="-40dp"
android:paddingEnd="0dp"
app:closeIcon="@drawable/ic_close"
app:iconifiedByDefault="false"
app:queryHint="@string/search_marinas"
app:searchIcon="@drawable/ic_null" />
</LinearLayout>
<ImageButton
android:id="@+id/marinasSearchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp"
android:background="@drawable/pin_back"
android:padding="12dp"
android:src="@drawable/ic_search"
android:tag="@string/defaultspin"
android:translationZ="5dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
动画从单个元素而不是全屏消失正是我想要的。
我解决了 problem.The 问题是添加一个额外的布局作为搜索视图应该 disappear.In 的父布局,这样它就会从周围布局的大小中消失本身,而不是主要布局。
<FrameLayout
android:id="@+id/marinasSearchFrame"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:outlineProvider="none"
android:translationX="15dp"
app:layout_constraintEnd_toStartOf="@+id/marinasSearchBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="@+id/marinasSearchLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
android:animateLayoutChanges="true"
android:background="@drawable/pin_back"
android:orientation="vertical"
android:outlineProvider="none"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:translationZ="5dp"
android:visibility="invisible">
<androidx.appcompat.widget.SearchView
android:id="@+id/marinasSearchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="-40dp"
android:paddingEnd="0dp"
app:closeIcon="@drawable/ic_close"
app:iconifiedByDefault="false"
app:queryHint="@string/search_marinas"
app:searchIcon="@drawable/ic_null" />
</LinearLayout>
</FrameLayout>
<ImageButton
android:id="@+id/marinasSearchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp"
android:background="@drawable/pin_back"
android:padding="12dp"
android:src="@drawable/ic_search"
android:tag="@string/defaultspin"
android:translationZ="5dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
我有一个按钮,单击 linearlayout.The 按钮后我使布局可见。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="700"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
再次点击时,我添加反方向的动画。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="false"
android:shareInterpolator="false">
<translate
android:duration="700"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="100%"
android:toYDelta="0%" />
</set>
我的流程 运行 很顺利,但是线性布局来自屏幕的 x 100 并从 x 消失 100.But 我想要的是按钮不会出现在其 size.For 之外,我如何编辑它,就好像它正在进入只有动画的按钮,而不创建可扩展布局?
<LinearLayout
android:id="@+id/marinasSearchLinear"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="2dp"
android:animateLayoutChanges="false"
android:background="@drawable/pin_back"
android:orientation="vertical"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:translationZ="5dp"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="@+id/marinasSearchBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.SearchView
android:id="@+id/marinasSearchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="-40dp"
android:paddingEnd="0dp"
app:closeIcon="@drawable/ic_close"
app:iconifiedByDefault="false"
app:queryHint="@string/search_marinas"
app:searchIcon="@drawable/ic_null" />
</LinearLayout>
<ImageButton
android:id="@+id/marinasSearchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp"
android:background="@drawable/pin_back"
android:padding="12dp"
android:src="@drawable/ic_search"
android:tag="@string/defaultspin"
android:translationZ="5dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
动画从单个元素而不是全屏消失正是我想要的。
我解决了 problem.The 问题是添加一个额外的布局作为搜索视图应该 disappear.In 的父布局,这样它就会从周围布局的大小中消失本身,而不是主要布局。
<FrameLayout
android:id="@+id/marinasSearchFrame"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:outlineProvider="none"
android:translationX="15dp"
app:layout_constraintEnd_toStartOf="@+id/marinasSearchBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="@+id/marinasSearchLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="20dp"
android:animateLayoutChanges="true"
android:background="@drawable/pin_back"
android:orientation="vertical"
android:outlineProvider="none"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:translationZ="5dp"
android:visibility="invisible">
<androidx.appcompat.widget.SearchView
android:id="@+id/marinasSearchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="-40dp"
android:paddingEnd="0dp"
app:closeIcon="@drawable/ic_close"
app:iconifiedByDefault="false"
app:queryHint="@string/search_marinas"
app:searchIcon="@drawable/ic_null" />
</LinearLayout>
</FrameLayout>
<ImageButton
android:id="@+id/marinasSearchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginEnd="15dp"
android:background="@drawable/pin_back"
android:padding="12dp"
android:src="@drawable/ic_search"
android:tag="@string/defaultspin"
android:translationZ="5dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />