編輯:關於Android編程
ViewAnimator繼承了FrameLayout,多個組件重合在一起,可以加入多個組件,然後切換的時候會有動畫。
ViewSwitcher繼承了ViewAnimator,組件重疊。
setFactory()方法可以設置ViewFactory(ViewSwitcher.ViewFactory),用ViewFactroy來實現View。
package peng.liu.test;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import java.util.ArrayList;
public class MainActivity extends Activity {
public static final int NUMBER_PER_SCREEN = 12;
public static class DataItem{
public String dataName;
public Drawable drawable;
}
private ArrayList list = new ArrayList();
private int screenNo = -1;
private int screenCount;
ViewSwitcher viewSwitcher;
LayoutInflater infalter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
for(int i = 0;i<40;i++){
String lable = ""+i;
Drawable drawableTwo = getResources().getDrawable(R.drawable.ic_launcher);
DataItem item = new DataItem();
item.dataName = lable;
item.drawable = drawableTwo;
list.add(item);
}
screenCount = list.size() % NUMBER_PER_SCREEN == 0 ? list.size()/NUMBER_PER_SCREEN:list.size()/NUMBER_PER_SCREEN+1;
viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);
viewSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
return infalter.inflate(R.layout.slide,null);
}
});
next(null);
}
public void next(View view){
if (screenNo < screenCount - 1){
screenNo++;
viewSwitcher.setInAnimation(this,R.anim.slide_in);
viewSwitcher.setOutAnimation(this,R.anim.slide_out);
(GridView)(viewSwitcher.getNextView()).setAdapter(adapter);
viewSwitcher.showNext();
}
}
public void prev(View view){
if (screenNo > 0){
screenNo--;
viewSwitcher.setInAnimation(this,R.anim.slide_in);
viewSwitcher.setOutAnimation(this,R.anim.slide_out);
(GridView)(viewSwitcher.getNextView()).setAdapter(adapter);
viewSwitcher.showNext();
}
}
public BaseAdapter adapter = new BaseAdapter() {
@Override
public int getCount() {
if (screenNo == screenCount-1&&list.size()%NUMBER_PER_SCREEN != 0 ){
return list.size()/NUMBER_PER_SCREEN;
}else{
return NUMBER_PER_SCREEN;
}
}
@Override
public DataItem getItem(int i) {
return list.get(screenNo*NUMBER_PER_SCREEN+i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
View view = convertView;
if (convertView == null){
view = infalter.inflate(R.layout.slide,null);
}
ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
imageView.setImageDrawable(getItem(i).drawable);
TextView text = (TextView) view.findViewById(R.id.textView);
text.setText(getItem(i).dataName);
return view;
}
};
}
本文實例講述了Android編程實現TCP客戶端的方法。分享給大家供大家參考,具體如下:因為項目上需要實現一個TCP Client 端;在網上找好多例子基本上都是阻塞方式
前言在Android開發中,顏色資源分兩種:一種是自定義顏色,一種是使用系統給我們自帶的顏色自定義顏色Android中顏色值的定義是由透明度alpha和RGB(紅綠藍)三
今天和大家分享一下Android中Matrix的簡單用法,Matrix其實就是一個3*3的矩陣,利用這個矩陣對圖像操作。在Android中,為我們提供一些封裝好的方法可以
一直以來Android性能測試一直是Android測試中一個被一部分人遺忘,有被一部分人無可奈何的東西。在絕大部分的創業公司,性能測試基本上都是被遺忘的,因為功能測試和穩