2016-09-25 87 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 ..你剛剛擁有它!謝了哥們!很好的工作 –