GridView ScrollView ViewPager
来源:互联网 发布:龙誉移动大数据平台 编辑:程序博客网 时间:2024/06/02 00:34
Android高级控件——GridView ScrollView ViewPager (上)
GridView 网格视图,网格视图组件,九宫图显示数据表格(一种控件)
ScrollView滚动视图
是一个单一容器,只能包含一个组件。
ViewPager左右滑动
SlideMenu侧边栏
PullToRefreshListView下拉刷新
ListView新闻 原声列表视图
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:color="#fc03" android:state_pressed="true"/> <item android:color="#09090a"/></selector>
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:color="#f50202" android:width="1dp"/> <corners android:radius="9dp"/></shape>
[html] view plain copy
- <?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.jreduch7292.MainActivity">
- <ScrollView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scrollbars="none"
- >
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- >
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@mipmap/fnl"/>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="设置"
- android:textSize="30sp"
- android:layout_marginLeft="120dp"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="意见反馈"
- android:textSize="30sp"
- android:layout_marginLeft="30dp"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="列表显示摘要"
- android:textSize="30sp"
- />
- <CheckBox
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginLeft="150dp"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="字体大小"
- android:textSize="30sp"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="中"
- android:textSize="30sp"
- android:layout_marginLeft="190dp"
- />
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@mipmap/fhe2"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="列表页评论"
- android:textSize="30sp"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="不限"
- android:textSize="30sp"
- android:layout_marginLeft="130dp"
- />
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@mipmap/fhe2"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="2G/3G网络流量"
- android:textSize="30sp"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="节省流量"
- android:textSize="30sp"
- android:layout_marginLeft="10dp"
- />
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@mipmap/fhe2"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="清理缓存"
- android:textSize="30sp"
- />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="当前缓存2.48MB"
- android:textSize="30sp"
- />
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@mipmap/fhe2"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454"
- android:layout_marginTop="20dp">
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="推送通知"
- android:textSize="30sp"
- />
- <CheckBox
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginLeft="200dp"
- android:checked="true"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="互动插件"
- android:textSize="30sp"
- />
- <CheckBox
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginLeft="200dp"
- android:checked="true"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="自动优化阅读"
- android:textSize="30sp"
- />
- <CheckBox
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginLeft="140dp"
- android:checked="true"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="收藏时转发"
- android:textSize="30sp"
- />
- <CheckBox
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginLeft="170dp"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="顶踩时转发"
- android:textSize="30sp"
- />
- <CheckBox
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginLeft="170dp"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="收藏时转发"
- android:textSize="30sp"
- />
- <CheckBox
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginLeft="170dp"
- />
- </LinearLayout>
- <View
- android:layout_width="match_parent"
- android:layout_height="1dp"
- android:background="#565454" >
- </View>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="顶踩时转发"
- android:textSize="30sp"
- />
- <CheckBox
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginLeft="170dp"
- />
- </LinearLayout>
- </LinearLayout>
- </ScrollView>
- </RelativeLayout>
GridViewActivity程序代码
[java] view plain copy
- package com.example.jreduch7292;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.GridView;
- import android.widget.ImageView;
- import android.widget.SimpleAdapter;
- import android.widget.Toast;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- public class GridViewActivity extends AppCompatActivity {
- private GridView gv;
- private ImageView big;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_grid_view);
- gv=(GridView)findViewById(R.id.gv);
- big=(ImageView)findViewById(R.id.big);
- final List list=new ArrayList();
- Map map=new HashMap();
- map.put("img",R.mipmap.a);
- map.put("name","字母A");
- list.add(map);
- map=new HashMap();
- map.put("img",R.mipmap.b);
- map.put("name","字母B");
- list.add(map);
- map=new HashMap();
- map.put("img",R.mipmap.c);
- map.put("name","字母C");
- list.add(map);
- map=new HashMap();
- map.put("img",R.mipmap.d);
- map.put("name","字母D");
- list.add(map);
- map=new HashMap();
- map.put("img",R.mipmap.e);
- map.put("name","字母E");
- list.add(map);
- map=new HashMap();
- map.put("img",R.mipmap.f);
- map.put("name","字母F");
- list.add(map);
- map=new HashMap();
- map.put("img",R.mipmap.g);
- map.put("name","字母G");
- list.add(map);
- map=new HashMap();
- map.put("img",R.mipmap.h);
- map.put("name","字母H");
- list.add(map);
- /*
- 1.simpleAdapter使用的数据源必须继承Map接口
- 2.from参数的意思是指向数据源Map中的键
- 3.to 参数的意思是为布局中的控件Id赋值
- */
- SimpleAdapter sa=new SimpleAdapter(this,list,
- R.layout.grid_layout,
- new String[]{"img","name"},
- new int[]{R.id.iv,R.id.tv});
- gv.setAdapter(sa);
- gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Map map=(Map)list.get(position);
- Toast.makeText(getBaseContext(),""+map.get("name"),Toast.LENGTH_SHORT).show();
- Intent intent=new Intent(getBaseContext(),BigActivity.class);
- intent.putExtra("img",(int)map.get("img"));
- startActivity(intent);
- }
- });
- }
- }
setContentView(R.layout.activity_grid_view);程序代码
[html] view plain copy
- <?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.jreduch7292.GridViewActivity">
- <GridView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/gv"
- android:numColumns="auto_fit"
- android:stretchMode="columnWidth"
- android:columnWidth="100dp"
- android:horizontalSpacing="5dp"
- android:verticalSpacing="5dp"
- android:cacheColorHint="#00000000"
- android:listSelector="#00000000"
- android:scrollbars="none"
- ></GridView>
- </RelativeLayout>
/*1.simpleAdapter使用的数据源必须继承Map接口2.from参数的意思是指向数据源Map中的键3.to 参数的意思是为布局中的控件Id赋值 */SimpleAdapter sa=new SimpleAdapter(this,list, R.layout.grid_layout, new String[]{"img","name"}, new int[]{R.id.iv,R.id.tv});gv.setAdapter(sa);程序代码[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="100dp"
- android:scaleType="centerCrop"
- android:id="@+id/iv"
- android:src="@mipmap/ic_launcher"
- /><!--android:scaleType="centerCrop"等比例缩放-->
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/tv"
- android:gravity="center"
- android:text="测试"
- />
- </LinearLayout>
setContentView(R.layout.activity_big);程序代码 放大
[java] view plain copy
- package com.example.jreduch7292;
- import android.animation.ObjectAnimator;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.animation.BounceInterpolator;
- import uk.co.senab.photoview.PhotoView;
- public class BigActivity extends AppCompatActivity {
- private PhotoView big;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_big);
- big=(PhotoView)findViewById(R.id.big);
- Intent intent=getIntent();
- int imgId=intent.getIntExtra("img",R.mipmap.ic_launcher);
- big.setImageResource(imgId);
- //属性动画
- ObjectAnimator oja=ObjectAnimator.ofFloat(big,"rotation",0,360);
- oja.setDuration(3000);
- oja.setRepeatCount(0);
- //设置插补器
- oja.setInterpolator(new BounceInterpolator());
- oja.start();
- }
- }
[html] view plain copy
- <?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"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.example.jreduch7292.BigActivity">
- <uk.co.senab.photoview.PhotoView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/big" />
- </RelativeLayout>
GridViewTextActivityr程序代码
重点重点重点[java] view plain copy
- package com.example.jreduch7292;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.GridView;
- import android.widget.SimpleAdapter;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- public class GridViewTextActivityr extends AppCompatActivity {
- private GridView gv1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_grid_view_text_activityr);
- getSupportActionBar().hide();
- //隐藏ActionBar
- gv1=(GridView)findViewById(R.id.gv1);
- final List list=new ArrayList();
- Map map=new HashMap();
- map.put("name","推荐");
- list.add(map);
- map=new HashMap();
- map.put("name","热点");
- list.add(map);
- map=new HashMap();;
- map.put("name","体育");
- list.add(map);
- map=new HashMap();
- map.put("name","烟台");
- list.add(map);
- map=new HashMap();
- map.put("name","视频");
- list.add(map);
- map=new HashMap();
- map.put("name","汽车");
- list.add(map);
- map=new HashMap();
- map.put("name","订阅");
- list.add(map);
- map=new HashMap();
- map.put("name","社会");
- list.add(map);
- map=new HashMap();;
- map.put("name","财经");
- list.add(map);
- map=new HashMap();
- map.put("name","科技");
- list.add(map);
- map=new HashMap();
- map.put("name","健康");
- list.add(map);
- map=new HashMap();
- map.put("name","军事");
- list.add(map);
- map=new HashMap();
- map.put("name","彩票");
- list.add(map);
- map=new HashMap();
- map.put("name","国际");
- list.add(map);
- map=new HashMap();
- map.put("name","段子");
- list.add(map);
- map=new HashMap();
- map.put("name","科技");
- list.add(map);
- map=new HashMap();
- map.put("name","健康");
- list.add(map);
- map=new HashMap();
- map.put("name","军事");
- list.add(map);
- map=new HashMap();
- map.put("name","彩票");
- list.add(map);
- /*
- 1.simpleAdapter使用的数据源必须继承Map接口
- 2.from参数的意思是指向数据源Map中的键
- 3.to 参数的意思是为布局中的控件Id赋值
- */
- SimpleAdapter sa=new SimpleAdapter(this,list,
- R.layout.grid2_layout,
- new String[]{"name"},
- new int[]{R.id.tv});
- gv1.setAdapter(sa);
- }
- }
[html] view plain copy
- <?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.jreduch7292.GridViewTextActivityr">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/ll"
- android:orientation="horizontal"
- android:background="#b3a9a9"
- >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="我的频道"
- android:textSize="30dp"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="编辑"
- android:textColor="#f70808"
- android:textSize="25sp"
- android:layout_marginLeft="50dp"
- android:background="@drawable/bian"
- />
- <ImageView
- android:layout_width="50dp"
- android:layout_height="50dp"
- android:src="@mipmap/fhee"
- android:layout_marginLeft="20dp"
- />
- </LinearLayout>
- <GridView
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginTop="10dp"
- android:id="@+id/gv1"
- android:layout_below="@+id/ll"
- android:numColumns="4"
- android:stretchMode="columnWidth"
- android:columnWidth="100dp"
- android:horizontalSpacing="5dp"
- android:verticalSpacing="5dp"
- android:cacheColorHint="#00000000"
- android:listSelector="#00000000"
- android:scrollbars="none"
- android:layout_marginLeft="10dp"
- android:layout_marginRight="10dp"
- >
- </GridView>
- </RelativeLayout>
[html] view plain copy
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:layout_height="match_parent">
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/biankuan"
- android:id="@+id/tv"
- android:textColor="@color/red"
- android:textSize="20dp"
- />
- </LinearLayout>
[java] view plain copy
- package com.example.jreduch7292;
- import android.os.Bundle;
- import android.support.v4.view.ViewPager;
- import android.support.v7.app.AppCompatActivity;
- import android.widget.HorizontalScrollView;
- import android.widget.ImageView;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.Toast;
- import com.example.jreduch7292.adapter.MyViewPagerAdapter;
- import java.util.ArrayList;
- import java.util.List;
- public class ScrollViewActivity extends AppCompatActivity {
- private RadioGroup rg;
- private ViewPager vp;
- private List<ImageView> imgList;
- private MyViewPagerAdapter mp;
- private RadioButton rb1,rb2,rb3,rb4,rb5,rb6,rb7,rb8,rb9,rb10;
- private HorizontalScrollView hs;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_scroll_view);
- rb1=(RadioButton) findViewById(R.id.rb1);
- rb2=(RadioButton) findViewById(R.id.rb2);
- rb3=(RadioButton) findViewById(R.id.rb3);
- rb4=(RadioButton) findViewById(R.id.rb4);
- rb5=(RadioButton) findViewById(R.id.rb5);
- rb6=(RadioButton) findViewById(R.id.rb6);
- rb7=(RadioButton) findViewById(R.id.rb7);
- rb8=(RadioButton) findViewById(R.id.rb8);
- rb9=(RadioButton) findViewById(R.id.rb9);
- rb10=(RadioButton) findViewById(R.id.rb10);
- hs=(HorizontalScrollView)findViewById(R.id.hs);
- rg=(RadioGroup)findViewById(R.id.rg);
- vp=(ViewPager)findViewById(R.id.vp);
- vpInit();
- rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(RadioGroup group, int checkedId) {
- if (checkedId==R.id.rb1){
- vp.setCurrentItem(0);
- Toast.makeText(getBaseContext(),"推荐1",Toast.LENGTH_SHORT).show();
- } else if (checkedId==R.id.rb2){
- vp.setCurrentItem(1);
- Toast.makeText(getBaseContext(),"推荐2",Toast.LENGTH_SHORT).show();
- }
- else if (checkedId==R.id.rb3){
- vp.setCurrentItem(2);
- Toast.makeText(getBaseContext(),"推荐3",Toast.LENGTH_SHORT).show();
- }else{
- switch(checkedId){
- case R.id.rb4:
- vp.setCurrentItem(3);
- Toast.makeText(getBaseContext(),"推荐4",Toast.LENGTH_SHORT).show();
- break;
- case R.id.rb5:
- vp.setCurrentItem(4);
- Toast.makeText(getBaseContext(),"推荐5",Toast.LENGTH_SHORT).show();
- break;
- case R.id.rb6:
- Toast.makeText(getBaseContext(),"推荐6",Toast.LENGTH_SHORT).show();
- break;
- case R.id.rb7:
- Toast.makeText(getBaseContext(),"推荐7",Toast.LENGTH_SHORT).show();
- break;
- }
- }
- }
- });
- }
- public void vpInit(){
- imgList=new ArrayList<>();
- // HashMap map=new HashMap();
- // //Map map=new HashMap();
- // map.put("name",R.mipmap.eeo);
- // imgList.add(map);
- // SimpleAdapter sa=new SimpleAdapter();
- ImageView iv=new ImageView(this);
- iv.setImageResource(R.mipmap.zyfzyf);
- imgList.add(iv);
- iv=new ImageView(this);
- iv.setImageResource(R.mipmap.eet);
- imgList.add(iv);
- iv=new ImageView(this);
- iv.setImageResource(R.mipmap.eer);
- imgList.add(iv);
- iv=new ImageView(this);
- iv.setImageResource(R.mipmap.eep);
- imgList.add(iv);
- iv=new ImageView(this);
- iv.setImageResource(R.mipmap.eeq);
- imgList.add(iv);
- iv=new ImageView(this);
- iv.setImageResource(R.mipmap.eew);
- imgList.add(iv);
- iv=new ImageView(this);
- iv.setImageResource(R.mipmap.eex);
- imgList.add(iv);
- iv=new ImageView(this);
- iv.setImageResource(R.mipmap.eez);
- imgList.add(iv);
- iv=new ImageView(this);
- iv.setImageResource(R.mipmap.efa);
- imgList.add(iv);
- iv=new ImageView(this);
- iv.setImageResource(R.mipmap.efb);
- imgList.add(iv);
- mp=new MyViewPagerAdapter(imgList);
- vp.setAdapter(mp);
- vp.setCurrentItem(0);
- vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
- @Override
- public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- }
- @Override
- public void onPageSelected(int position) {
- RadioButton rb=(RadioButton) rg.getChildAt(position);
- rb.setChecked(true);
- }
- @Override
- public void onPageScrollStateChanged(int state) {
- }
- });
- }
- }
[html] view plain copy
- <?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.jreduch7292.ScrollViewActivity">
- <HorizontalScrollView
- android:layout_width="match_parent"
- android:layout_height="50dp"
- android:scrollbars="none"
- android:id="@+id/hs"
- >
- <RadioGroup
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal"
- android:id="@+id/rg">
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐1"
- android:id="@+id/rb1"
- android:button="@null"
- android:checked="true"
- android:textColor="@color/rdbt_text_color"
- android:gravity="center"
- />
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐2"
- android:id="@+id/rb2"
- android:button="@null"
- android:gravity="center"
- android:textColor="@color/rdbt_text_color"
- />
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐3"
- android:id="@+id/rb3"
- android:button="@null"
- android:gravity="center"
- android:textColor="@color/rdbt_text_color"
- />
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐4"
- android:id="@+id/rb4"
- android:button="@null"
- android:gravity="center"
- android:textColor="@color/rdbt_text_color"
- />
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐5"
- android:id="@+id/rb5"
- android:button="@null"
- android:gravity="center"
- android:textColor="@color/rdbt_text_color"
- />
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐6"
- android:id="@+id/rb6"
- android:button="@null"
- android:textColor="@color/rdbt_text_color"
- android:gravity="center"
- />
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐7"
- android:id="@+id/rb7"
- android:textColor="@color/rdbt_text_color"
- android:button="@null"
- android:gravity="center"
- />
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐8"
- android:id="@+id/rb8"
- android:button="@null"
- android:textColor="@color/rdbt_text_color"
- android:gravity="center"
- />
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐9"
- android:id="@+id/rb9"
- android:button="@null"
- android:textColor="@color/rdbt_text_color"
- android:gravity="center"
- />
- <RadioButton
- android:layout_width="50dp"
- android:layout_height="match_parent"
- android:text="推荐10"
- android:id="@+id/rb10"
- android:textColor="@color/rdbt_text_color"
- android:button="@null"
- android:gravity="center"
- />
- </RadioGroup>
- </HorizontalScrollView>
- <android.support.v4.view.ViewPager
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/vp"
- android:background="#efc60f"
- android:layout_below="@+id/hs"
- >
- </android.support.v4.view.ViewPager>
- </RelativeLayout>
SpinnerActivity 程序代码
[java] view plain copy
- package com.example.jreduch7292;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.Spinner;
- import android.widget.Toast;
- import java.util.ArrayList;
- import java.util.List;
- public class SpinnerActivity extends AppCompatActivity {
- private Spinner sp;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_spinner);
- sp=(Spinner)findViewById(R.id.sp);
- List cityList=new ArrayList();
- cityList.add("北京");
- cityList.add("上海");
- cityList.add("广州");
- //最简单的适配器只能显示一行文字
- ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_spinner_item,
- android.R.id.text1,cityList);
- sp.setAdapter(aa);
- sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- Toast.makeText(getBaseContext(),sp.getSelectedItem().toString(),Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
- });
- }
- }
[html] view plain copy
- <?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.jreduch7292.SpinnerActivity">
- <Spinner
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/sp1"
- android:entries="@array/city"
- ></Spinner>
- <Spinner
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/sp"
- android:layout_below="@+id/sp1"
- android:layout_alignParentStart="true"
- ></Spinner>
- </RelativeLayout>
</string><string-array name="city"> <item>烟台</item> <item>济南</item> <item>青岛</item></string-array>
0 0
- GridView ScrollView ViewPager
- 笔记67--ViewPager+ScrollView+ListView/GridView
- scrollview嵌套viewpager(包含gridview和listvie)
- viewpager、listview、gridview、scrollview去除阴影
- 解决ScrollView嵌套ListView,GridView,ViewPager
- GridView嵌套在ViewPager中,ViewPager嵌套在ScrollView中,GridView显示不全问题
- 【Android实战】ScrollView+GridView+ViewPager实现导航页
- Android高级控件——GridView ScrollView ViewPager (上)
- ListView WebView Viewpager GridView ScrollView 滑动冲突解决
- viewpager+scrollview
- android ScrollView嵌套viewpager,viewpager嵌套gridview,解决内嵌无法显示的问题
- GridView嵌套在ViewPager中,ViewPager嵌套在ScrollView中不显示
- viewpager+gridview
- ViewPager+GridView
- ScrollView嵌套ListView,GridView,ViewPager,以及这些控件自动滚动到底部问题的解决
- ScrollView 和 GridView冲突和ViewPager冲突解决和ListView冲突解决
- ListView,GridView,ScrollView,ViewPager去除滑动到底的蓝色阴影
- ScrollView嵌套ListView,GridView,ViewPager,以及这些控件自动滚动到底部问题的解决
- Exception raised during rendering:com/android/util/PropertiesMap解决方法
- 统计学习方法第4,5章笔记
- Android ImageView的scaleType属性解释
- 关于bootstrap中tab的使用
- nyoj 97 兄弟旅游问题
- GridView ScrollView ViewPager
- 使用MyBatis-Generator自动创建代码(参考+修改)
- 实验八:VLAN的配置和单臂路由
- Visual Studio 2012 - Visual C++ MFC 类
- linux查看网卡速度和模式调整
- Oracle基本的SQL语句
- playframework1.2.x博客教程(一)-创建项目
- SDUT2140图结构练习——判断给定图是否存在合法拓扑序列
- 程序人生之一:一个四年 JAVA 程序员的工作经历