Android - 如何仅在背景图像中添加动画(放大)而不影响其他人?

时间:2015-02-03 10:58:32

标签: android xml android-animation

我正在考虑制作应用的第一个视图:它只是一个基本的搜索视图,其中包含一个EditText和两个Button。当用户留在此视图,键入或无操作时,我希望背景图像放大和缩小。

所以我添加了zoomin.xml并将动画设置为视图。缩放正在发挥作用,但唯一的问题是它正在缩放一切。我知道这是因为我在xml的根元素中设置了背景图片,但我不知道如何只在不影响其他视图的情况下放大背景图片。

这是我在root元素中的背景图片代码。

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="@drawable/bcg2"
android:orientation="vertical"
android:gravity="center">

所以我在想是否有任何浮动视图会这样做?但我不知道该怎么做。还是其他任何建议?

谢谢!

1 个答案:

答案 0 :(得分:2)

使用全屏ImageView而不是Linearlayout的背景属性并仅缩放图像

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/image_to_zoom"
        android:src="@drawable/bcg2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity"
        android:orientation="vertical"
        android:gravity="center"/>

</RelativeLayout>