2016-09-25 100 views
1

我有一个View和我想要闪烁特定时间的边框。我试图让闪烁,但问题是整个视图闪烁。我知道它的细节我在里面提到了View这个背景设置为边框。视图的闪烁边框

下面是代码:

xml: 
<LinearLayout 
     android:layout_width="14dp" 
     android:layout_height="14dp 
     android:id="@+id/rect2" 
     android:background="@drawable/cir" 
     > 

     <View 
      android:layout_width="5dp" 
      android:layout_height="5dp" 
      android:background="#14FFFFFF" 
      android:layout_marginTop="3dp" 
      android:layout_marginLeft="3dp" 
      android:id="@+id/inrect2" 
     /> 
    </LinearLayout> 

的java:

//somecode 
      setContentView(R.layout.activity_main); 
      re2=(LinearLayout)findViewById(R.id.rect2); 
      myView2= findViewById(R.id.inrect2); 

     ((GradientDrawable)re1.getBackground()).setStroke(1,Color.WHITE); 
        AlphaAnimation blinkanimation= new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible 
        blinkanimation.setDuration(500); // duration - half a second 
        blinkanimation.setInterpolator(new LinearInterpolator()); // do not alter animation rate 
        blinkanimation.setRepeatCount(28); // Repeat animation infinitely 
        blinkanimation.setRepeatMode(Animation.REVERSE); 
        re1.startAnimation(blinkanimation); 

re1.startAnimation(blinkanimation)似乎开始动画整个线性布局,反正我有可以闪烁仅边界? 任何帮助,将不胜感激!谢谢!

回答

1

而不是闪烁视图,尝试闪烁外部线性布局,视图和线性布局应该填充它们之间,以便给出一个边界效果。

[编辑]

尝试使用FrameLayout,该LinearLayout应稍大模拟边框般的效果上的LinearLayout顶部堆叠View

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <Linearlayout 
    android:background="#00000000" 
    android:layout_gravity="center" 
    android:layout_width="20dp" 
    android:layout_height="20dp" 
/> 

    <View 
    android:layout_width="16dp" 
    android:layout_height="16dp" 
    android:layout_gravity="center" 
    android:gravity="center" 
    android:background="#AA000000" /> 

</FrameLayout> 
+0

编辑的代码,是的,我已经填充,我可以看到在XML中的视图的外线。问题是我如何只动画Linearlayout而不是在里面查看? –

+0

我看到了,然后使用framelayout将视图堆叠在linearlayout的顶部,并检查它是否有效。 –

+0

WOW ..你刚刚拥有它!谢了哥们!很好的工作 –