概述
packagegto.ImageSwitchTest;importjava.io.File;importjava.io.FileReader;importandroid.R.drawable;importandroid.app.Activity;importandroid.graphics.drawable.Drawable;importandroid.os.Bundle;importandroid.os.Environment;importandroid.text.AlteredCharSequence;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.FrameLayout;importandroid.widget.ImageSwitcher;importandroid.widget.ImageView;importandroid.widget.RelativeLayout;importandroid.widget.RelativeLayout.LayoutParams;importandroid.widget.ViewSwitcher.ViewFactory;publicclassImageSwitchTestextendsActivityimplementsOnClickListener,ViewFactory{/**Called when the activity is first created.*/privateFile[] m_imgList;privateImageSwitcher m_ImageSwitch;privatestaticintm_picIndex;privatestaticintIMAGESWITCHER_ID=0x123456;privatestaticintButtonStartID=0x2000000;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//创建一个相对布局RelativeLayout main_View=newRelativeLayout(this);//创建一个ImageSwitcherm_ImageSwitch=newImageSwitcher(this);//在相对布局中添加图片切换器RelativeLayout.LayoutParams param=newRelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
main_View.addView(m_ImageSwitch,param);
m_ImageSwitch.setId(IMAGESWITCHER_ID);
m_ImageSwitch.setFactory(this);
File file=Environment.getExternalStorageDirectory();
String strPic=file+"\mag\mag01\";
File magdir=newFile(strPic);
m_imgList=magdir.listFiles();
Drawable myDrawable=Drawable.createFromPath(m_imgList[m_picIndex].toString());
m_ImageSwitch.setImageDrawable(myDrawable);
setContentView(main_View);//创建按钮intcount=m_imgList.length;for(inti=count-1; i>=0;--i)
{
Button btn=newButton(this);
btn.setId(ButtonStartID+i);
btn.setText(Integer.toString(i));
btn.setOnClickListener(this);
param=newRelativeLayout.LayoutParams(20,20);if( count-1==i ){
param.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
}else{
param.addRule(RelativeLayout.LEFT_OF,ButtonStartID+i+1);
}
param.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
btn.setLayoutParams(param);
main_View.addView(btn,param);
}
}
@OverridepublicvoidonClick(View v) {//TODO Auto-generated method stubm_picIndex=v.getId()-ButtonStartID;
Drawable myDrawable=Drawable.createFromPath(m_imgList[m_picIndex].toString());
m_ImageSwitch.setImageDrawable(myDrawable);
}
@OverridepublicView makeView() {//TODO Auto-generated method stubreturnnewImageView(this);
}
}
最后
以上就是健忘砖头为你收集整理的java代码实现布局_java代码实现相对布局的全部内容,希望文章能够帮你解决java代码实现布局_java代码实现相对布局所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复