Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何按位置变换线性布局背景_Android - Fatal编程技术网

Android 如何按位置变换线性布局背景

Android 如何按位置变换线性布局背景,android,Android,我很难找到这个问题的答案 我想模拟ImageView中图像的转换,例如 image1 = (ImageView) findViewById(R.id.image1); animationSlideInLeft = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left); image1.startAnimation(animationSlideInLeft); 但那不是我想要的。相反,我想将可绘制集转换为线性布局背景 lin

我很难找到这个问题的答案

我想模拟
ImageView
中图像的转换,例如

image1 = (ImageView) findViewById(R.id.image1);
animationSlideInLeft = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left);
image1.startAnimation(animationSlideInLeft);
但那不是我想要的。相反,我想将
可绘制
集转换为
线性布局
背景

linearLayout.setBackground(drawable); 

如何转换
可绘制的
并使其在线性布局内部从左向右移动?

我不确定这是否适用于您所追求的内容,但您是否考虑过在
线性布局内部设置
图像视图
,并使其高度和宽度与
线性布局
而不是设置
线性布局
背景?您可以像现在一样设置
图像视图的动画,它将给出相同的结果。

您可以使用RelativeLayout或AbsoluteLayout,在其中放置一个图像(覆盖其父对象),然后装载活动的当前布局。现在,如果您为该图像设置动画,则活动的背景似乎会设置动画。
例如,假设这是活动的当前布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/vg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

在这里可以找到:

是的
左侧的幻灯片是一个xml文件。但这不是先决条件。我只需要一个解决方案。我已经想到了,但是如何将线性布局中的小部件覆盖在图像视图上呢?您必须将
LinearLayout
包装在
RelativeLayout
中。将
ImageView
放在
RelativeLayout
中,将视图的其余部分放在
LinearLayout中
谢谢,您的回答是正确的,但请在前面回答,并建议使用相对布局。尽管如此,我还是对你的评论和回答投了赞成票。谢谢。事实上,我在他之前回答了-检查x分钟前回答的问题。但是别担心!谢谢你的投票!啊,直到评论出来,我才提到相对论——明白了!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/vg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >



    <ImageView
        android:id="@+id/img1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_x="0dp"
        android:layout_y="0dp"
        android:src="@drawable/bright_sun" />
    <LinearLayout
    android:id="@+id/vg2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

        <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
    </LinearLayout>

</RelativeLayout>