[英]Add view to translucent linearlayout
我很难理解如何为半透明的LinearLayout
创建添加动画。 有两个具有不透明度和运动背景的视图(如果重要,请使用Google地图)。 View1是LinearLayout
并且将view2添加到view1。 但是,在添加view2时,可以通过view1看到它(请参见下面的左动画)。
有什么办法可以防止这种情况正确实现动画? (目标:请参见右侧的动画)。请记住,背景正在变化并且不是固定的图片。
最好的问候拉瓦
我想我的评论可能还不是很清楚,所以我整理了一个简单的例子来更好地解释和演示。 由于我不确定您的View
是什么,因此我将它们保留为通用名称,并设置了一些您想更改的硬编码属性。
main.xml
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/stripes_diag" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000" >
<TextView android:id="@+id/view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="#88ffffff"
android:textColor="#000000"
android:textSize="40sp"
android:text="Lorem Ipsum" />
</LinearLayout>
<View android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#88ffffff" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Animate"
android:onClick="onClick" />
</LinearLayout>
</RelativeLayout>
MainActivity
类:
public class MainActivity extends Activity
{
View view1, view2;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view1 = findViewById(R.id.view1);
view2 = findViewById(R.id.view2);
}
public void onClick(View v)
{
view2.setY(view2.getHeight());
ObjectAnimator anim = ObjectAnimator.ofFloat(view2, "y", 0);
anim.setDuration(1500);
anim.start();
}
}
看一下效果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.