前面兩篇文章都是關於幻燈片是怎麼實現的,但是效果都不是非常理想,結合前兩次的知識我自定義了乙個view把功能封裝了一下更方便**的使用與修改.**如下:
import android.content.context;
import android.util.attributeset;
import android.view.view;
import android.view.animation.alphaanimation;
import android.view.animation.animation;
import android.view.animation.animationset;
import android.view.animation.scaleanimation;
import android.view.animation.animation.animationlistener;
import android.widget.imageview;
import android.widget.relativelayout;
public class slideview extends relativelayout
public slideview(context context, attributeset attrs)
public void setdata(int urls, int index)
private void setview()
//開始幻燈片
public void nextanimation()
scaleanimation scale = new scaleanimation(1.0f, 1.5f, 1.0f, 1.5f,
animation.relative_to_self, 0.5f, animation.relative_to_self,
0.5f);
scale.setduration(3000);
scale.setfillafter(true);
animationset animationset = new animationset(true);
alphaanimation alpha = new alphaanimation(1.0f, 0.0f);
alpha.setduration(3000);
alpha.setfillafter(true);
alpha.setanimationlistener(new animationlistener()
}@override
public void onanimationrepeat(animation animation)
@override
public void onanimationend(animation animation)
});animationset.addanimation(scale);
animationset.addanimation(alpha);
imagetop.startanimation(animationset);
} private void setimagedownanimation()
@override
public void onanimationrepeat(animation animation)
@override
public void onanimationend(animation animation)
});animationset.addanimation(scale);
animationset.addanimation(alpha);
imagedown.startanimation(animationset);
} //獲取換燈片的執行到那個位置
public int getindex()
//結束幻燈片
public void stopanim()
}
**非常簡單也有注釋,希望能夠幫到大家. Android自定義View實現
android自定義view實現很簡單 繼承view或者其子類,重寫建構函式 ondraw,onmeasure 等函式,根據繼承的類的不同可能有所不同。如果自定義的view需要有自定義的屬性,需要在values下建立attrs.xml。在其中定義你的屬性。在使用到自定義view的xml布局檔案中需要...
自定義View的實現
自定義view分為三種型別 0 繼承現有的ui控制項 實現特定功能,例如事件攔截,就像是我的slidingpanelayout和viewpager結合 自定義view 0 繼承現有的控制項 1 將多個控制項進行組合,形成新的自定義view radio動態指示器,radiobutton的自定義?自定義...
自定義View實現陰影
其實實現陰影android系統自帶android elevation實現陰影功能,但是在低版本系統可能就無效了,當然還可以使用shape.xml實現,cardview也可以實行陰影功能,但是尷尬的是不知道怎麼切換陰影的顏色。上圖中圖一是使用setshadowlayer實現的陰影效果 上圖中圖二是使用...