package com.example.text12;
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
public class MainActivity extends Activity {
private PopupWindow pw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void show(View v){
View view = View.inflate(this, R.layout.popup, null);
GridView gv =(GridView) view.findViewById(R.id.gv);
gv.setAdapter(new MyAdapter());
gv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?>parent,View view,
int position,long id){
}
});
pw = new PopupWindow(view,
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setFocusable(true);
//显示
// pw.showAsDropDown(v);
pw.showAtLocation((View)v.getParent(), Gravity.BOTTOM, 0, 0);
}
class MyAdapter extends BaseAdapter{
private int [] images =new int[]{
R.drawable.i1,
R.drawable.i2,
R.drawable.i3,
R.drawable.i4,
R.drawable.i5,
R.drawable.i6,
R.drawable.i7,
R.drawable.i8,
};
private String [] names = new String[]{
"搜索管理","文件管理","下载管理","全屏管理","网址管理","书签管理","界面管理","加入界面"
};
@Override
public int getCount() {
// TODO Auto-generated method stub
return names.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return names;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView == null){
convertView = View.inflate(MainActivity.this,
R.layout.item, null);
}
ImageView iv_icon = (ImageView) convertView.findViewById(R.id.iv_icon);
TextView iv_name = (TextView) convertView.findViewById(R.id.iv_name);
iv_icon.setImageResource(images[position]);
iv_name.setText(names[position]);
return convertView;
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示"
android:onClick="show"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/bg"
android:gravity="center"
>
<GridView
android:id="@+id/gv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="4"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
></GridView>
</LinearLayout>
————————————————————————————————————————————————————
package com.example.text11;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SlidingDrawer;
public class MainActivity extends Activity {
private GridView gridView;
private SlidingDrawer slidingDrawer;
private ImageView imageView;
private int[] icons={
R.drawable.f1, R.drawable.f2,
R.drawable.f3, R.drawable.f4,
R.drawable.f5, R.drawable.f6,
R.drawable.f7, R.drawable.f8,
R.drawable.f9
};
private String[] items={
"Phone", "Message", "AddImage", "Music", "Telephone", "SMS"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView)findViewById(R.id.mycontent);
slidingDrawer = (SlidingDrawer)findViewById(R.id.sliding_drawer);
imageView = (ImageView)findViewById(R.id.my_image);
MyGridViewAdapter adapter = new MyGridViewAdapter(this, items, icons);
gridView.setAdapter(adapter);
slidingDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
public void onDrawerOpened() {
imageView.setImageResource(R.drawable.right1);
}
});
slidingDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
public void onDrawerClosed() {
imageView.setImageResource(R.drawable.left1);
}
});
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
}
package com.example.text11;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MyGridViewAdapter extends BaseAdapter{
private Context context;
private String[] items;
private int[] icons;
public MyGridViewAdapter(Context context, String[] items, int[] icons){
this.context = context;
this.items = items;
this.icons = icons;
}
public int getCount() {
return items.length;
}
public Object getItem(int arg0) {
return items[arg0];
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater layoutInflater = LayoutInflater.from(context);
View view = (View)layoutInflater .inflate(R.layout.grid, null);
ImageView imageView = (ImageView)view.findViewById(R.id.image_view);
TextView textview = (TextView)view.findViewById(R.id.text_view);
imageView.setImageResource(icons[position]);
textview.setText(items[position]);
return view;
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="抽屉效果"
android:gravity="center"
android:textSize="20sp"
/>
<SlidingDrawer
android:id="@+id/sliding_drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:handle="@+id/layout1"
android:content="@+id/mycontent"
android:orientation="horizontal"
>
<LinearLayout
android:id="@id/layout1"
android:layout_width="35px"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#00000000"
>
<ImageView
android:id="@+id/my_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/left1"
/>
</LinearLayout>
<GridView
android:id="@id/mycontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20dip"
android:numColumns="3"
android:gravity="center"
android:background="#ff000000"
/>
</SlidingDrawer>
</RelativeLayout>
————————————————————————————————————————————————————
package com.example.text10;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
/**
* Created by ZWH on 2016/5/16.
*/
public class GalleryAdapter extends BaseAdapter {
private Context mContext;
//设置要展示的图片资源
int[] images = {R.drawable.f1, R.drawable.f2, R.drawable.f3, R.drawable.f4};
public GalleryAdapter(Context context) {
this.mContext = context;
}
@Override
public int getCount() {
return images.length;
}
@Override
public Object getItem(int i) {
return i;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
//在此最好判断一下view是否为空
ImageView image = new ImageView(mContext);
image.setImageResource(images[i]);
image.setAdjustViewBounds(true);//设置调整视图的边界
//设置宽高
image.setLayoutParams(new Gallery.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return image;
}
}
package com.example.text10;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.Toast;
public class MainActivity extends Activity {
GalleryAdapter galleryAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Gallery gallery = (Gallery) findViewById(R.id.gallery);
galleryAdapter = new GalleryAdapter(MainActivity.this);
gallery.setAdapter(galleryAdapter);
//相应的点击事件
gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(MainActivity.this, "您点击的是" + i, Toast.LENGTH_LONG).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mytest.MainActivity">
<Gallery
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
————————————————————————————————————————————————————
package com.example.app07_en;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
public String[] groupStrings = {"西游记", "水浒传", "三国演义", "红楼梦"};
public String[][] childStrings = {
{"唐三藏", "孙悟空", "猪八戒", "沙和尚"},
{"宋江", "林冲", "李逵", "鲁智深"},
{"曹操", "刘备", "孙权", "诸葛亮", "周瑜"},
{"贾宝玉", "林黛玉", "薛宝钗", "王熙凤"}
};
private ExpandableListView expand_list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
我们自定义两个布局 一个Group.xml
一个 child .xml 布局
在activity_main.xml中
···
<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/expand_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ExpandableListView>
···
-------------child.xml---------------
···
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label_expand_child"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="20dp"
android:textColor="@android:color/white"
<TextView xmlns:android=" http://schemas.android.com/apk/res/android"
android:id="@+id/label_expand_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@android:color/holo_blue_light"
android:paddingLeft="20dp"
android:textColor="@android:color/white"
android:textSize="20sp" />
————————————————————————————————————————————————————
package com.example.test10_gallery;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class GalleryAdapter extends BaseAdapter {
private Context mContext;
//设置要展示的图片资源
int[] images = {R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher};
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/android"
xmlns:tools=" http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mytest.MainActivity">
</RelativeLayout>
···
**************MainActivity*************中代码如下----------
···
package com.example.test10_gallery;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.Toast;
public class MainActivity extends Activity {
GalleryAdapter galleryAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Gallery gallery = (Gallery) findViewById(R.id.gallery);
————————————————————————————————————————————————————
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
spinner=(Spinner) findViewById(R.id.spinner);
————————————————————————————————————————————————————————
————————————————————————————————————————————————————————