当前位置:网站首页>Functions and usage of viewswitch
Functions and usage of viewswitch
2022-07-07 17:36:00 【XLMN】
ViewSwitcher The function and usage of
Represents the view switching component , Multiple view Stack up , Show only one component at a time , When control from one view Switch to another view when , You can specify animation effects ,
To give viewswitcher Add multiple components , Use viewswitcher Of setfactory Method setting viewfactory, And by the viewfactory establish view
public class MainActivity extends Activity {
// Define a constant , Number of applications per screen
public static final int NUMBER_PER_SCREEN = 12;
// Internal classes representing the application
public static class DataItem {
// Application name
public String dataName;
// App icons
public Drawable drawble;
}
// Save the list aggregate
private ArrayList<DataItem> items = new ArrayList<MainActivity.DataItem>();
// Record which screen is currently being displayed ,
private int sceeNo = -1;
// Total number of screens saved
private int screenCount;
ViewSwitcher vs;
// establish Layoutinflater object
LayoutInflater inflater;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.viewswitcher);
inflater = LayoutInflater.from(MainActivity.this);
// Create a containing 40 An element of liset aggregate , Used to simulate inclusion 40 Applications
for (int i = 0; i < 40; i++) {
String label = "" + i;
Drawable dr = getResources().getDrawable(R.drawable.mia5);
DataItem dt = new DataItem();
dt.dataName = label;
dt.drawble = dr;
items.add(dt);
}
// Calculate the total number of screens the application occupies
// The energy of the computing application can be divided NUMBER_PER_SCREEN;
// If it's not divisible , The total number of screens should be the result of division plus 1;
screenCount=items.size()%NUMBER_PER_SCREEN == 0?
items.size()/NUMBER_PER_SCREEN:
items.size()/NUMBER_PER_SCREEN +1;
vs=(ViewSwitcher) findViewById(R.id.viewswitcher);
vs.setFactory(new ViewFactory() {
// Return to one GridView Components
@Override
public View makeView() {
// TODO Auto-generated method stub
// Load components , The actual is GridView Components
return inflater.inflate(R.layout.slidelistview, null);
}
});
// The first screen is displayed when the page is loaded
next(null);
}
public void next(View view) {
// TODO Auto-generated method stub
if (sceeNo < screenCount - 1) {
sceeNo++;
// by ViewSwitcher Animate the component display process
vs.setInAnimation(this, R.anim.slide_in_right);
// by ViewSwitcher Animate the process of component hiding
vs.setInAnimation(this, R.anim.slide_out_left);
// Control what will be displayed on the next screen GridView Corresponding adapter
((GridView) vs.getNextView()).setAdapter(ba);
// Click the button on the right , Show next screen
// After learning gesture detection , You can also use gestures to display the next screen
vs.showNext();
}
}
public void prev(View v) {
// TODO Auto-generated method stub
if (sceeNo > 0) {
sceeNo--;
// by viewswitcher Animate the component display process
vs.setInAnimation(this, android.R.anim.slide_in_left);
// by viewswitcher Animate the process of component hiding
vs.setInAnimation(this, android.R.anim.slide_in_left);
// Control what will be displayed on the next screen gridview Corresponding adapter
((GridView) vs.getNextView()).setAdapter(ba);
// Click the left button to display the previous screen , You can also use gestures
// After learning gesture detection , You can also realize the previous screen through gesture detection
vs.showPrevious();
}
}
// The baseAdapter Responsible for the display of each screen GridView Provide list items
private BaseAdapter ba = new BaseAdapter() {
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
View view = arg1;
if (arg1 == null) {
// Load the layout file
view = inflater.inflate(R.layout.labelicon,
null);
}
// Get the layout I see in imageview Components , And set the icon for it
ImageView iv = (ImageView) view
.findViewById(R.id.image01);
iv.setImageDrawable(getItem(arg0).drawble);
// obtain
TextView tv = (TextView) view
.findViewById(R.id.textview);
tv.setText(getItem(arg0).dataName);
return view;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
//
return arg0;
}
@Override
public DataItem getItem(int arg0) {
// TODO Auto-generated method stub
// according to screenno Computation first argo List item data
return items.get(sceeNo * NUMBER_PER_SCREEN + arg0);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
// If you have reached the last screen , And the number of applications cannot be divided number——per_screen
if (sceeNo == screenCount - 1
&& items.size() % NUMBER_PER_SCREEN != 0) {
// The number of programs displayed on the last screen is the number of applications number_per_screen Seeking remainder
return items.size() % NUMBER_PER_SCREEN;
}
// Otherwise, the number of programs displayed on each screen is number_per_screen
return NUMBER_PER_SCREEN;
}
};
}
<?xml version="1.0" encoding="utf-8"?><!-- Define a Viewswitcher -->
<ViewSwitcher
android:id="@+id/viewswitcher"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ViewSwitcher>
<!-- Define buttons to scroll to the previous screen -->
<Button
android:id="@+id/but01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:onClick="prev"
android:text="&1t" />
<Button
android:id="@+id/but02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="next"
android:text="&gt" />
<?xml version="1.0" encoding="utf-8"?> <ImageView
android:id="@+id/image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" />
<?xml version="1.0" encoding="utf-8"?> <!-- Animate drag in from right ,duration Specify the duration of the animation -->
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0" />
<?xml version="1.0" encoding="utf-8"?> <!-- Animate the drag in from the left ,duration Specify the duration of the animation -->
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="-100%p"
android:toXDelta="0" />
<?xml version="1.0" encoding="utf-8"?> 
边栏推荐
- Sator推出Web3游戏“Satorspace” ,并上线Huobi
- 【网络攻防原理与技术】第4章:网络扫描技术
- 99% 用户在 Power BI 云端报表常犯错误
- With the latest Alibaba P7 technology system, mom doesn't have to worry about me looking for a job anymore
- Biped robot controlled by Arduino
- 科普达人丨一文弄懂什么是云计算?
- Solidity 开发环境搭建
- Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
- Seaborn data visualization
- DNS series (I): why does the updated DNS record not take effect?
猜你喜欢

麒麟信安加入宁夏商用密码协会

Sator a lancé le jeu web 3 "satorspace" et a lancé huobi

2021-06-28
![[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial](/img/14/4e7ebfb1ed5b99f8377af9d17d2177.jpg)
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial

本周小贴士#136:无序容器

【网络攻防原理与技术】第6章:特洛伊木马
Share the latest high-frequency Android interview questions, and take you to explore the Android event distribution mechanism

麒麟信安云平台全新升级!

第3章业务功能开发(用户登录)

Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
随机推荐
MySQL implements the query of merging two fields into one field
TabHOST 选项卡的功能和用法
Sator推出Web3游戏“Satorspace” ,并上线Huobi
PLC:自动纠正数据集噪声,来洗洗数据集吧 | ICLR 2021 Spotlight
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
【网络攻防原理与技术】第5章:拒绝服务攻击
第3章业务功能开发(用户访问项目)
99%的人都不知道|私有化部署还永久免费的即时通讯软件!
麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
【饭谈】Web3.0到来后,测试人员该何去何从?(十条预言和建议)
【可信计算】第十二次课:TPM授权与会话
mysql官网下载:Linux的mysql8.x版本(图文详解)
Sator launched Web3 game "satorspace" and launched hoobi
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
alertDialog創建对话框
【源码解读】| LiveListenerBus源码解读
本周小贴士#141:注意隐式转换到bool
LeetCode 890(C#)
[source code interpretation] | source code interpretation of livelistenerbus
AI来搞财富分配比人更公平?来自DeepMind的多人博弈游戏研究