Textview
2015年1月5日
13:01
packagecom.example.test;
importorg.xml.sax.XMLReader;
importandroid.app.Activity;
importandroid.graphics.drawable.BitmapDrawable;
importandroid.graphics.drawable.Drawable;
importandroid.os.Bundle;
importandroid.text.Editable;
importandroid.text.Html;
importandroid.text.Html.ImageGetter;
importandroid.text.Html.TagHandler;
importandroid.widget.TextView;
importandroid.widget.Toast;
importcom.example.testview.R;
public classTextActivity extends Activity{
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
//TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
showTextView();
}
privatevoid showTextView(){
ImageGetterimageGetter=new Html.ImageGetter() {
@Override
publicDrawable getDrawable(String source) {
if(source!=null){
//TODO Auto-generated method stub
BitmapDrawableretureDrawable=(BitmapDrawable)getResources().getDrawable(R.drawable.ic_launcher);
retureDrawable.setBounds(0,0, retureDrawable.getIntrinsicWidth(), retureDrawable.getIntrinsicWidth());
returnretureDrawable;
}
else{
returnnull;
}
}
};
TagHandlertagHandler=new Html.TagHandler() {
@Override
publicvoid handleTag(boolean opening, String tag, Editable output,
XMLReaderxmlReader) {
//TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"手势不存在", 0).show();
}
};
TextViewtextView1=(TextView)findViewById(R.id.textView1);
textView1.setText(Html.fromHtml("<b>zhongguoni hao </b><h1>riben</h><fontcoloor='#000'>meiguonihao</font><imgsrc='http://pic.aigou.com/upload/blog/2010/07/28/17033448.snap_m.jpg'/><h>sadsa</h>",imageGetter,tagHandler));
}
}
源码看看吧,有用的。
用这个代码可以一样的效果
private voidshowTextView(){
TextViewtextView1=(TextView)findViewById(R.id.textView1);
SpannableStringBuilderspannableStringBuilder=new SpannableStringBuilder("sadadasdda");
ImageSpanimageSpan=new ImageSpan(getApplicationContext(), R.drawable.ic_launcher);
spannableStringBuilder.setSpan(imageSpan,2, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView1.setText(spannableStringBuilder);
}
}
这样写可以做一个点击文字的事件
private voidshowTextView(){
TextViewtextView1=(TextView)findViewById(R.id.textView1);
SpannableStringBuilderspannableStringBuilder=new SpannableStringBuilder("#sa#dadasdda");
ClickableSpanclickableSpan=new ClickableSpan() {
@Override
publicvoid onClick(View widget) {
// TODOAuto-generated method stub
Toast.makeText(getApplicationContext(),"手势不存在", 3000).show();
}
};
ImageSpanimageSpan=new ImageSpan(getApplicationContext(), R.drawable.ic_launcher);
spannableStringBuilder.setSpan(imageSpan,2, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spannableStringBuilder.setSpan(clickableSpan,0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView1.setText(spannableStringBuilder);
}
}
Button
2015年1月23日
1:38
点击效果改变在资源中建立新的button
<?xmlversion="1.0" encoding="utf-8"?>
<selectorxmlns:android="http://schemas.android.com/apk/res/android" >
<itemandroid:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/mv1"/>
<itemandroid:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/mv1"/>
<itemandroid:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/mv10"/>
<itemandroid:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/mv10"/>
<itemandroid:drawable="@drawable/mv1"/>
</selector>
在layout中
吧button的地址改成
新建的资源名字。
长点和短点
private void showButton(){
Buttonbutton1=(Button) findViewById(R.id.button1);
button1.setOnLongClickListener(newOnLongClickListener() {
@Override
publicboolean onLongClick(View v) {
// TODOAuto-generated method stub
Toast.makeText(getApplicationContext(),"手势不存在", 0).show();
return true;//注意是true不然会同时执行onClick。
}
});
button1.setOnClickListener(newOnClickListener() {
@Override
publicvoid onClick(View v) {
// TODOAuto-generated method stub
Toast.makeText(getApplicationContext(),"在", 0).show();
}
});
}
ToggleButton
2015年1月23日
2:00
private void showTb() {
toggleButton=(ToggleButton)findViewById(R.id.toggleButton1);
toggleButton.setOnCheckedChangeListener(newOnCheckedChangeListener() {
@Override
publicvoid onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//TODO Auto-generated method stub
if(isChecked){
Toast.makeText(getApplicationContext(),"手势不存在", 2000).show();
toggleButton.setBackgroundResource(R.drawable.mv1);
}
else{
Toast.makeText(getApplicationContext(),"手势", 2000).show();
toggleButton.setBackgroundResource(R.drawable.mv11);
}
}
});
}
这个用法其实跟button差不多
不过这个要新建私有的ToggleButton
checkBOX是跟这个一样的很容易。
RadioBox
2015年1月23日
2:29
private voidshowRb() {
RadioGroupradioGroup=(RadioGroup) findViewById(R.id.radioGroup1);
radioGroup.setOnCheckedChangeListener(newRadioGroup.OnCheckedChangeListener() {
@Override
publicvoid onCheckedChanged(RadioGroup group, int checkedId) {
//TODO Auto-generated method stub
switch(checkedId) {
caseR.id.radio0:
Toast.makeText(getApplicationContext(),"手势不存在", 0).show();
caseR.id.radio1:
Toast.makeText(getApplicationContext(),"不存在", 0).show();
caseR.id.radio2:
Toast.makeText(getApplicationContext(),"手势", 0).show();
default:
break;
}
其实都一样的玩很简单
Adapter
2015年1月23日
11:03
这是一个用BaseAdapter的用法例子
<<UserAdapter.java>>
<<User.java>>
<<Acccc.java>>
Spinner
2015年1月23日
11:18
这里是设置一个spinner在layout加入一个位置。
在string里
<string-arrayname="spinnername">
<item>Hello</item>
<item>fw</item>
<item>ww</item>
<item>ffff</item>
<item>ff</item>
<item>faf</item>
</string-array>
然后这个事方法。(这只有文字)
private void showSp(){
Spinnerspinner=(Spinner) findViewById(R.id.spinner1);
//建立数据源
String[]myItemsStrings=getResources().getStringArray(R.array.spinnername);
//建立Adapter,连接了数据源
ArrayAdapter<String>adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, myItemsStrings);
//绑定adapter到UI组件
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(newOnItemSelectedListener() {
@Override
publicvoid onItemSelected(AdapterView<?> parent, View arg1,
intposition, long id) {
//TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),((TextView) arg1).getText().toString(), 2000).show();
}
@Override
publicvoid onNothingSelected(AdapterView<?> parent) {
//TODO Auto-generated method stub
}
});
}
自定义的adpter
privatevoid showSpinner2() {
Spinnerspinner=(Spinner) findViewById(R.id.spinner1);
ArrayList<User>users=newArrayList<User>();
users.add(newUser("dasd","asda"));
users.add(newUser("g","f"));
users.add(newUser("d","s"));
users.add(newUser("ff","v"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
users.add(newUser("g","c"));
UserAdapteruserAdapter=new UserAdapter(this, users);
spinner.setAdapter(userAdapter);
}
在这里
<<UserAdapter.java>>
<<User.java>>
ProgressBar
2015年1月23日
14:30
了解一下吧
直接在layout中设置
<ProgressBar
android:id="@+id/progressBar1"
android:indeterminate="true"
android:progress="30"
android:secondaryProgress="50"
style="@android:style/Widget.ProgressBar.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
SeekBar
2015年1月23日
14:37
privatevoid showSeekBar(){
mSeekBar=(SeekBar)findViewById(R.id.seekBar1);
mSeekBar.setOnSeekBarChangeListener(newOnSeekBarChangeListener() {
@Override
publicvoid onStopTrackingTouch(SeekBar seekBar) {
//TODO Auto-generated method stub
Log.i("dsad","start:"+seekBar.getProgress());
}
@Override
publicvoid onStartTrackingTouch(SeekBar seekBar) {
//TODO Auto-generated method stub
}
@Override
publicvoid onProgressChanged(SeekBar seekBar, int progress,
booleanfromUser) {
//TODO Auto-generated method stub
}
});
}
这里的三个方法运用
在layout中
<SeekBar
android:id="@+id/seekBar1"
android:thumb="@drawable/ic_launcher"
android:progress="10"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
QuickContactBadge
2015年1月23日
15:03
这是个链接的空间通常用于做头像
private void showQC(){
QuickContactBadgeqcb=(QuickContactBadge) findViewById(R.id.quickContactBadge1);
qcb.assignContactFromPhone("1516515",true);
}
layout中直接设置即可
<QuickContactBadge
android:id="@+id/quickContactBadge1"
android:src="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
RateBar
2015年1月23日
15:04
采用这个方法
private void RB() {
RatingBarratingBar=(RatingBar) findViewById(R.id.ratingBar1);
ratingBar.setOnRatingBarChangeListener(newOnRatingBarChangeListener() {
@Override
publicvoid onRatingChanged(RatingBar ratingBar, float rating,
booleanfromUser) {
//TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"Rate:"+rating,0).show();
}
});
}
控件的形状控制及EditText
2015年1月23日
15:26
<?xmlversion="1.0" encoding="utf-8"?>
<shape
android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solidandroid:color="#FF0000"></solid>
<cornersandroid:radius="5dp"></corners>
</shape>
以上是在drawable中建立的相当于TextView中的空间修改
这是简单的EditText
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入"
android:background="@drawable/hil"
android:ems="10"
android:inputType="textEmailAddress" />
一个有用的方法
editText.setOnEditorActionListener(newOnEditorActionListener() {
@Override
publicboolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"手势不存在", 0).show();
returnfalse;
}
});
}
AutoCompleteTextView
2015年1月23日
15:28
private voidshowAC() {
AutoCompleteTextViewautoCompleteTextView=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
//建立数据源
String[]counties=new String[]{
"sd","cacscc",
"asdada","wqad",
"wq","cas",
"e","sad",
"f","sad" ,
"sd","vas" ,
"fa","ewq" ,
"fwq","sad" ,
"qwd","a" ,
"cas","sad" ,
"e","fs" ,
"q","rq" ,
"fw","sad" ,
"qweqw","vwq"
};
//建立Adapter并且绑定数据源
ArrayAdapter<String>adapter=new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
//绑定ui
autoCompleteTextView.setAdapter(adapter);
}
ListView1
2015年1月23日
16:01
继承ListActivity
public class ccc extendsListActivity{
privateEditText mEditText;
List<String>itemsList;
ArrayAdapter<String>adapter;
@Override
protectedvoid onListItemClick(ListView l, View v, int position, long id) {
// TODOAuto-generated method stub
super.onListItemClick(l,v, position, id);
}
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
// TODOAuto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.nnnn);
displayList();
// ListViewlvListView;
}
/*
private voiddisplayCursor() {
Cursorcursor=getContentResolver().query(android.provider.Contacts.Phones.CONTENT_URI,null, null, null, null);
SimpleCursorAdapteradapter=new SimpleCursorAdapter(this, R.layout.ss, cursor, newString[]{Phones.NAME,Phones.NUMBER}, new int[]{R.id.textView6,R.id.textView7});
setListAdapter(adapter);
}这个方法可以实现读取信息这里读的是手机通讯录
*/
privatevoid displayList(){
// mListView=getListView();
itemsList=newArrayList<String>();
adapter=newArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice,itemsList);
setListAdapter(adapter);
mEditText=(EditText)findViewById(R.id.editTextss);
mEditText.setOnKeyListener(newOnKeyListener() {
@Override
publicboolean onKey(View v, int keyCode, KeyEvent event) {
// TODOAuto-generated method stub
if(keyCode==KeyEvent.KEYCODE_ENTER&&event.getAction()==KeyEvent.ACTION_UP){
itemsList.add(mEditText.getText().toString());
adapter.notifyDataSetChanged();
mEditText.setText(null);
}
returnfalse;
}
});
}
}
这个代码用于添加
public class ccc extendsListActivity{
privateEditText mEditText;
List<String>itemsList;
ArrayAdapter<String>adapter;
@Override
protectedvoid onListItemClick(ListView l, View v, int position, long id) {
// TODOAuto-generated method stub
//这里点击删除
super.onListItemClick(l,v, position, id);
itemsList.remove(position);
adapter.notifyDataSetChanged();
}
这里点击删除
GridView
2015年1月30日
1:44
package cjs.ui;
importcom.example.lista.R;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.widget.BaseAdapter;
importandroid.widget.GridView;
importandroid.widget.ImageView;
public classMyGridViewActivity extends Activity{
privateint[] mImages=newint[]{R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher};
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
//TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.grid);
GridViewgridView1=(GridView) findViewById(R.id.gridView1);
gridView1.setAdapter(newImageAdatper());
}
classImageAdatper extends BaseAdapter{
@Override
publicint getCount() {
//TODO Auto-generated method stub
returnmImages.length;
}
@Override
publicObject getItem(int position) {
//TODO Auto-generated method stub
returnmImages[position];
}
@Override
publiclong getItemId(int position) {
//TODO Auto-generated method stub
returnposition;
}
@Override
publicView getView(int position, View convertView, ViewGroup parent) {
//TODO Auto-generated method stub
ImageViewimageView=new ImageView(MyGridViewActivity.this);
imageView.setImageResource(mImages[position]);
returnimageView;
}}
}
layout是
<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView
android:id="@+id/gridView1"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:numColumns="auto_fit"
>
</GridView>
</LinearLayout>
ExpandableListView
2015年1月30日
0:28
在一个listview当中点击展开的效果
简单实现
importjava.util.ArrayList;
importjava.util.HashMap;
importjava.util.List;
importandroid.app.ExpandableListActivity;
importandroid.os.Bundle;
importandroid.widget.ExpandableListAdapter;
importandroid.widget.SimpleExpandableListAdapter;
public classExpandabListActivity extends ExpandableListActivity{
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
//TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//设置数据源
List<HashMap<String,String>>groupData=new ArrayList<HashMap<String,String>>();
HashMap<String,String>map1=new HashMap<String,String>();
map1.put("Name","cjs");
groupData.add(map1);
map1=newHashMap<String,String>();
map1.put("Name","ds");
groupData.add(map1);
map1=newHashMap<String,String>();
map1.put("Name","daa");
groupData.add(map1);
map1=newHashMap<String,String>();
map1.put("Name","dd");
groupData.add(map1);
map1=newHashMap<String,String>();
map1.put("Name","dddd");
groupData.add(map1);
List<List<HashMap<String,String>>>childData=new ArrayList<List<HashMap<String,String>>>();
List<HashMap<String,String>>childItem=new ArrayList<HashMap<String,String>>();
HashMap<String,String>map2=new HashMap<String,String>();
map2.put("Name","cjs");
childData.add(childItem);
map2.put("Name","ds");
childData.add(childItem);
map2.put("Name","daa");
childData.add(childItem);
map2.put("Name","dd");
childData.add(childItem);
map2.put("Name","dddd");
childData.add(childItem);
childItem.add(map2);
//建立数据源
ExpandableListAdapteradapter=new SimpleExpandableListAdapter(this, groupData,android.R.layout.simple_expandable_list_item_1,android.R.layout.simple_expandable_list_item_1,
newString[]{"Name","Address"}, new int[]{android.R.id.text1},childData, android.R.layout.simple_expandable_list_item_2,
newString[]{"Name","Address"}, new int[]{android.R.id.text2});
//绑定界面
setListAdapter(adapter);
}
}
ScrollView
2015年1月30日
2:21
让整个layout变成可滑动在最上面把layout改成这个
<ScrollViewandroid:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
Tab
2015年1月30日
2:37
菜单切换效果
package cjs.ui;
importandroid.app.Activity;
importandroid.app.TabActivity;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.widget.TabHost;
importandroid.widget.TabHost.TabSpec;
public class MYTabextends TabActivity{
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
//TODO Auto-generated method stub
super.onCreate(savedInstanceState);
TabHosttabHost1=getTabHost();
TabSpectabSpec1=tabHost1.newTabSpec("Tab1").setIndicator("Tab11",getResources().getDrawable(android.R.drawable.ic_dialog_email))
.setContent(newIntent(this,Slic.class));
tabHost1.addTab(tabSpec1);
TabSpectabSpec2=tabHost1.newTabSpec("Tab2").setIndicator("Tab22",getResources().getDrawable(android.R.drawable.ic_dialog_map))
.setContent(newIntent(this,MyGridViewActivity.class));
tabHost1.addTab(tabSpec2);
}
@Override
protectedvoid onChildTitleChanged(Activity childActivity,
CharSequencetitle) {
//TODO Auto-generated method stub
super.onChildTitleChanged(childActivity,title);
}
@Override
publicvoid onContentChanged() {
//TODO Auto-generated method stub
super.onContentChanged();
}
}
在layout中直接加入一个Tab就可以了
WebView
2015年1月30日
11:36
WebViewview1=new WebView(this);
view1.loadUrl("http://www.hao123.com/8080");
ImageButton
2015年1月30日
11:49
可以用background设置背景透明直接加“”这个
Gallery
2015年1月30日
11:54
;
importcom.example.lista.R;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.webkit.WebView;
importandroid.widget.AdapterView;
importandroid.widget.AdapterView.OnItemClickListener;
importandroid.widget.BaseAdapter;
importandroid.widget.Gallery;
importandroid.widget.ImageView;
public class Slicextends Activity{
privateint[] mImages=newint[]{R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher};
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
//TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.pl);
//
// WebViewview1=new WebView(this);
// view1.loadUrl("http://www.hao123.com/8080");
Gallerygallery1=(Gallery) findViewById(R.id.gallery1);
gallery1.setAdapter(newImageAdatper());
gallery1.setOnItemClickListener(newOnItemClickListener() {
@Override
publicvoid onItemClick(AdapterView<?> parent, View view, int position,
longid) {
//TODO Auto-generated method stub
}
});
}
classImageAdatper extends BaseAdapter{
@Override
publicint getCount() {
//TODO Auto-generated method stub
returnmImages.length;
}
@Override
publicObject getItem(int position) {
//TODO Auto-generated method stub
returnmImages[position];
}
@Override
publiclong getItemId(int position) {
//TODO Auto-generated method stub
returnposition;
}
@Override
publicView getView(int position, View convertView, ViewGroup parent) {
//TODO Auto-generated method stub
ImageViewimageView=new ImageView(Slic.this);
imageView.setImageResource(mImages[position]);
returnimageView;
}}
publicvoid onItemClick(AdapterView<?> arg0, View view, int position,
longid) {
//TODO Auto-generated method stub
Intentintent = null;
switch(position)
{
case0:intent = new Intent(arg0.getContext(), ExpandabListActivity.class);break;
case1:intent = new Intent(arg0.getContext(), ExpandabListActivity.class);break;
}
startActivity(intent);
}
}
layout直接建立一个Gallery加个id。
ImageSwitcher
2015年1月30日
12:11
实现点击下面
上面播放的效果就是点击切换
importcom.example.lista.R;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.webkit.WebView;
importandroid.widget.AdapterView;
importandroid.widget.AdapterView.OnItemClickListener;
importandroid.widget.BaseAdapter;
importandroid.widget.Gallery;
importandroid.widget.ImageSwitcher;
importandroid.widget.ImageView;
importandroid.widget.ViewSwitcher.ViewFactory;
public class Slicextends Activity implements ViewFactory{
privateint[] mImages=newint[]{R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.a,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher,R.drawable.ic_launcher};
privateint mIndex = 0;
privateImageSwitcher imageSwitcher1;
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pl);
imageSwitcher1=(ImageSwitcher)findViewById(R.id.slidingDrawer1);
imageSwitcher1.setFactory(this);
imageSwitcher1.setImageResource(mImages[mIndex]);
Gallerygallery1=(Gallery) findViewById(R.id.gallery1);
gallery1.setAdapter(newImageAdatper());
gallery1.setOnItemClickListener(newOnItemClickListener() {
@Override
publicvoid onItemClick(AdapterView<?> parent, View view, int position,
longid) {
imageSwitcher1.setImageResource(mImages[position]);
}
});
}
classImageAdatper extends BaseAdapter{
@Override
publicint getCount() {
returnmImages.length;
}
@Override
publicObject getItem(int position) {
returnmImages[position];
}
@Override
publiclong getItemId(int position) {
//TODO Auto-generated method stub
returnposition;
}
@Override
publicView getView(int position, View convertView, ViewGroup parent) {
ImageViewimageView=new ImageView(Slic.this);
imageView.setImageResource(mImages[position]);
returnimageView;
}}
@Override
publicView makeView() {
//TODO Auto-generated method stub
returnnew ImageView(this);
}
}
layout中应该是
<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageSwitcher
android:layout_width="fill_parent"
android:layout_height="333dp"
android:id="@+id/slidingDrawer1"
android:layout_gravity="center"
android:background="@drawable/ic_launcher"
android:inAnimation="@android:anim/fade_in"
android:outAnimation="@android:anim/fade_out" >
</ImageSwitcher>
<Gallery
android:layout_width="match_parent"
android:id="@+id/gallery1"
android:layout_height="match_parent"
>
</Gallery>
</LinearLayout>
Layout
2015年1月30日
12:51
RelativeLayout
是相对布局
TableLayout
实战菜单menu
2015年1月30日
13:14
现在来说没什么用着菜单
Dialog
2015年1月30日
13:25
2015年1月31日
0:35
sliding
2015年1月31日
0:47
向上拉的Activity
<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<SlidingDrawer
android:id="@+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:content="@+id/content"
android:handle="@+id/handle">
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle"/>
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>