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
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     tools:context="com.example.jreduch7292.MainActivity">  
  7. <ScrollView  
  8.     android:layout_width="match_parent"  
  9.     android:layout_height="match_parent"  
  10.     android:scrollbars="none"  
  11.     >  
  12.     <LinearLayout  
  13.         android:layout_width="match_parent"  
  14.         android:layout_height="wrap_content"  
  15.         android:orientation="vertical"  
  16.         >  
  17.         <LinearLayout  
  18.             android:layout_width="match_parent"  
  19.             android:layout_height="wrap_content"  
  20.             android:orientation="horizontal"  
  21.             >  
  22.             <ImageView  
  23.                 android:layout_width="wrap_content"  
  24.                 android:layout_height="wrap_content"  
  25.                 android:src="@mipmap/fnl"/>  
  26.             <TextView  
  27.                 android:layout_width="wrap_content"  
  28.                 android:layout_height="wrap_content"  
  29.                 android:text="设置"  
  30.                 android:textSize="30sp"  
  31.                 android:layout_marginLeft="120dp"  
  32.                 />  
  33.             <TextView  
  34.                 android:layout_width="wrap_content"  
  35.                 android:layout_height="wrap_content"  
  36.                 android:text="意见反馈"  
  37.                 android:textSize="30sp"  
  38.                 android:layout_marginLeft="30dp"  
  39.                 />  
  40.             </LinearLayout>  
  41.         <View  
  42.             android:layout_width="match_parent"  
  43.             android:layout_height="1dp"  
  44.            android:background="#565454" >  
  45.         </View>  
  46.         <LinearLayout  
  47.             android:layout_width="match_parent"  
  48.             android:layout_height="wrap_content"  
  49.             android:orientation="horizontal"  
  50.             >  
  51.         <TextView  
  52.             android:layout_width="wrap_content"  
  53.             android:layout_height="wrap_content"  
  54.             android:text="列表显示摘要"  
  55.             android:textSize="30sp"  
  56.             />  
  57.             <CheckBox  
  58.                 android:layout_width="30dp"  
  59.                 android:layout_height="30dp"  
  60.                 android:layout_marginLeft="150dp"  
  61.                 />  
  62.     </LinearLayout>  
  63.         <View  
  64.             android:layout_width="match_parent"  
  65.             android:layout_height="1dp"  
  66.             android:background="#565454" >  
  67.         </View>  
  68.         <LinearLayout  
  69.             android:layout_width="match_parent"  
  70.             android:layout_height="wrap_content"  
  71.             android:orientation="horizontal"  
  72.             >  
  73.             <TextView  
  74.                 android:layout_width="wrap_content"  
  75.                 android:layout_height="wrap_content"  
  76.                 android:text="字体大小"  
  77.                 android:textSize="30sp"  
  78.                 />  
  79.             <TextView  
  80.                 android:layout_width="wrap_content"  
  81.                 android:layout_height="wrap_content"  
  82.                 android:text="中"  
  83.                 android:textSize="30sp"  
  84.                 android:layout_marginLeft="190dp"  
  85.                 />  
  86.            <ImageView  
  87.                android:layout_width="wrap_content"  
  88.                android:layout_height="wrap_content"  
  89.                android:src="@mipmap/fhe2"  
  90.                />  
  91.         </LinearLayout>  
  92.         <View  
  93.             android:layout_width="match_parent"  
  94.             android:layout_height="1dp"  
  95.             android:background="#565454" >  
  96.         </View>  
  97.         <LinearLayout  
  98.             android:layout_width="match_parent"  
  99.             android:layout_height="wrap_content"  
  100.             android:orientation="horizontal"  
  101.             >  
  102.             <TextView  
  103.                 android:layout_width="wrap_content"  
  104.                 android:layout_height="wrap_content"  
  105.                 android:text="列表页评论"  
  106.                 android:textSize="30sp"  
  107.                 />  
  108.             <TextView  
  109.                 android:layout_width="wrap_content"  
  110.                 android:layout_height="wrap_content"  
  111.                 android:text="不限"  
  112.                 android:textSize="30sp"  
  113.                 android:layout_marginLeft="130dp"  
  114.                 />  
  115.             <ImageView  
  116.                 android:layout_width="wrap_content"  
  117.                 android:layout_height="wrap_content"  
  118.                 android:src="@mipmap/fhe2"  
  119.                 />  
  120.         </LinearLayout>  
  121.         <View  
  122.             android:layout_width="match_parent"  
  123.             android:layout_height="1dp"  
  124.             android:background="#565454" >  
  125.         </View>  
  126.         <LinearLayout  
  127.             android:layout_width="match_parent"  
  128.             android:layout_height="wrap_content"  
  129.             android:orientation="horizontal"  
  130.             >  
  131.             <TextView  
  132.                 android:layout_width="wrap_content"  
  133.                 android:layout_height="wrap_content"  
  134.                 android:text="2G/3G网络流量"  
  135.                 android:textSize="30sp"  
  136.                 />  
  137.             <TextView  
  138.                 android:layout_width="wrap_content"  
  139.                 android:layout_height="wrap_content"  
  140.                 android:text="节省流量"  
  141.                 android:textSize="30sp"  
  142.                 android:layout_marginLeft="10dp"  
  143.                 />  
  144.             <ImageView  
  145.                 android:layout_width="wrap_content"  
  146.                 android:layout_height="wrap_content"  
  147.                 android:src="@mipmap/fhe2"  
  148.                 />  
  149.         </LinearLayout>  
  150.         <View  
  151.             android:layout_width="match_parent"  
  152.             android:layout_height="1dp"  
  153.             android:background="#565454" >  
  154.         </View>  
  155.         <LinearLayout  
  156.             android:layout_width="match_parent"  
  157.             android:layout_height="wrap_content"  
  158.             android:orientation="horizontal"  
  159.             >  
  160.             <TextView  
  161.                 android:layout_width="wrap_content"  
  162.                 android:layout_height="wrap_content"  
  163.                 android:text="清理缓存"  
  164.                 android:textSize="30sp"  
  165.                 />  
  166.             <TextView  
  167.                 android:layout_width="wrap_content"  
  168.                 android:layout_height="wrap_content"  
  169.                 android:text="当前缓存2.48MB"  
  170.                 android:textSize="30sp"  
  171.   
  172.                 />  
  173.             <ImageView  
  174.                 android:layout_width="wrap_content"  
  175.                 android:layout_height="wrap_content"  
  176.                 android:src="@mipmap/fhe2"  
  177.                 />  
  178.         </LinearLayout>  
  179.         <View  
  180.             android:layout_width="match_parent"  
  181.             android:layout_height="1dp"  
  182.             android:background="#565454" >  
  183.         </View>  
  184.         <View  
  185.             android:layout_width="match_parent"  
  186.             android:layout_height="1dp"  
  187.             android:background="#565454"  
  188.             android:layout_marginTop="20dp">  
  189.         </View>  
  190.         <LinearLayout  
  191.             android:layout_width="match_parent"  
  192.             android:layout_height="wrap_content"  
  193.             android:orientation="horizontal"  
  194.             >  
  195.   
  196.             <TextView  
  197.                 android:layout_width="wrap_content"  
  198.                 android:layout_height="wrap_content"  
  199.                 android:text="推送通知"  
  200.                 android:textSize="30sp"  
  201.                 />  
  202.             <CheckBox  
  203.                 android:layout_width="30dp"  
  204.                 android:layout_height="30dp"  
  205.                 android:layout_marginLeft="200dp"  
  206.                 android:checked="true"  
  207.                 />  
  208.         </LinearLayout>  
  209.         <View  
  210.             android:layout_width="match_parent"  
  211.             android:layout_height="1dp"  
  212.             android:background="#565454" >  
  213.         </View>  
  214.         <LinearLayout  
  215.             android:layout_width="match_parent"  
  216.             android:layout_height="wrap_content"  
  217.             android:orientation="horizontal"  
  218.             >  
  219.             <TextView  
  220.                 android:layout_width="wrap_content"  
  221.                 android:layout_height="wrap_content"  
  222.                 android:text="互动插件"  
  223.                 android:textSize="30sp"  
  224.                 />  
  225.             <CheckBox  
  226.                 android:layout_width="30dp"  
  227.                 android:layout_height="30dp"  
  228.                 android:layout_marginLeft="200dp"  
  229.                 android:checked="true"  
  230.                 />  
  231.         </LinearLayout>  
  232.         <View  
  233.             android:layout_width="match_parent"  
  234.             android:layout_height="1dp"  
  235.             android:background="#565454" >  
  236.         </View>  
  237.         <LinearLayout  
  238.             android:layout_width="match_parent"  
  239.             android:layout_height="wrap_content"  
  240.             android:orientation="horizontal"  
  241.             >  
  242.             <TextView  
  243.                 android:layout_width="wrap_content"  
  244.                 android:layout_height="wrap_content"  
  245.                 android:text="自动优化阅读"  
  246.                 android:textSize="30sp"  
  247.                 />  
  248.             <CheckBox  
  249.                 android:layout_width="30dp"  
  250.                 android:layout_height="30dp"  
  251.                 android:layout_marginLeft="140dp"  
  252.                 android:checked="true"  
  253.                 />  
  254.         </LinearLayout>  
  255.         <View  
  256.             android:layout_width="match_parent"  
  257.             android:layout_height="1dp"  
  258.             android:background="#565454" >  
  259.         </View>  
  260.         <LinearLayout  
  261.             android:layout_width="match_parent"  
  262.             android:layout_height="wrap_content"  
  263.             android:orientation="horizontal"  
  264.             >  
  265.             <TextView  
  266.                 android:layout_width="wrap_content"  
  267.                 android:layout_height="wrap_content"  
  268.                 android:text="收藏时转发"  
  269.                 android:textSize="30sp"  
  270.                 />  
  271.             <CheckBox  
  272.                 android:layout_width="30dp"  
  273.                 android:layout_height="30dp"  
  274.                 android:layout_marginLeft="170dp"  
  275.                 />  
  276.         </LinearLayout>  
  277.         <View  
  278.             android:layout_width="match_parent"  
  279.             android:layout_height="1dp"  
  280.             android:background="#565454" >  
  281.         </View>  
  282.         <LinearLayout  
  283.             android:layout_width="match_parent"  
  284.             android:layout_height="wrap_content"  
  285.             android:orientation="horizontal"  
  286.             >  
  287.             <TextView  
  288.                 android:layout_width="wrap_content"  
  289.                 android:layout_height="wrap_content"  
  290.                 android:text="顶踩时转发"  
  291.                 android:textSize="30sp"  
  292.                 />  
  293.             <CheckBox  
  294.                 android:layout_width="30dp"  
  295.                 android:layout_height="30dp"  
  296.                 android:layout_marginLeft="170dp"  
  297.                 />  
  298.         </LinearLayout>  
  299.         <View  
  300.             android:layout_width="match_parent"  
  301.             android:layout_height="1dp"  
  302.             android:background="#565454" >  
  303.         </View>  
  304.         <LinearLayout  
  305.             android:layout_width="match_parent"  
  306.             android:layout_height="wrap_content"  
  307.             android:orientation="horizontal"  
  308.             >  
  309.             <TextView  
  310.                 android:layout_width="wrap_content"  
  311.                 android:layout_height="wrap_content"  
  312.                 android:text="收藏时转发"  
  313.                 android:textSize="30sp"  
  314.                 />  
  315.             <CheckBox  
  316.                 android:layout_width="30dp"  
  317.                 android:layout_height="30dp"  
  318.                 android:layout_marginLeft="170dp"  
  319.                 />  
  320.         </LinearLayout>  
  321.         <View  
  322.             android:layout_width="match_parent"  
  323.             android:layout_height="1dp"  
  324.             android:background="#565454" >  
  325.         </View>  
  326.         <LinearLayout  
  327.             android:layout_width="match_parent"  
  328.             android:layout_height="wrap_content"  
  329.             android:orientation="horizontal"  
  330.             >  
  331.             <TextView  
  332.                 android:layout_width="wrap_content"  
  333.                 android:layout_height="wrap_content"  
  334.                 android:text="顶踩时转发"  
  335.                 android:textSize="30sp"  
  336.                 />  
  337.             <CheckBox  
  338.                 android:layout_width="30dp"  
  339.                 android:layout_height="30dp"  
  340.                 android:layout_marginLeft="170dp"  
  341.                 />  
  342.         </LinearLayout>  
  343.     </LinearLayout>  
  344. </ScrollView>  
  345.   
  346. </RelativeLayout>  




GridViewActivity程序代码
[java] view plain copy
在CODE上查看代码片派生到我的代码片
  1. package com.example.jreduch7292;  
  2.   
  3. import android.content.Intent;  
  4. import android.os.Bundle;  
  5. import android.support.v7.app.AppCompatActivity;  
  6. import android.view.View;  
  7. import android.widget.AdapterView;  
  8. import android.widget.GridView;  
  9. import android.widget.ImageView;  
  10. import android.widget.SimpleAdapter;  
  11. import android.widget.Toast;  
  12.   
  13. import java.util.ArrayList;  
  14. import java.util.HashMap;  
  15. import java.util.List;  
  16. import java.util.Map;  
  17.   
  18. public class GridViewActivity extends AppCompatActivity {  
  19. private GridView gv;  
  20.     private ImageView big;  
  21.     @Override  
  22.     protected void onCreate(Bundle savedInstanceState) {  
  23.         super.onCreate(savedInstanceState);  
  24.         setContentView(R.layout.activity_grid_view);  
  25.   
  26.         gv=(GridView)findViewById(R.id.gv);  
  27. big=(ImageView)findViewById(R.id.big);  
  28.         final List list=new ArrayList();  
  29.         Map map=new HashMap();  
  30.         map.put("img",R.mipmap.a);  
  31.         map.put("name","字母A");  
  32.         list.add(map);  
  33.         map=new HashMap();  
  34.         map.put("img",R.mipmap.b);  
  35.         map.put("name","字母B");  
  36.         list.add(map);  
  37.          map=new HashMap();  
  38.         map.put("img",R.mipmap.c);  
  39.         map.put("name","字母C");  
  40.         list.add(map);  
  41.          map=new HashMap();  
  42.         map.put("img",R.mipmap.d);  
  43.         map.put("name","字母D");  
  44.         list.add(map);  
  45.         map=new HashMap();  
  46.         map.put("img",R.mipmap.e);  
  47.         map.put("name","字母E");  
  48.         list.add(map);  
  49.         map=new HashMap();  
  50.         map.put("img",R.mipmap.f);  
  51.         map.put("name","字母F");  
  52.         list.add(map);  
  53.         map=new HashMap();  
  54.         map.put("img",R.mipmap.g);  
  55.         map.put("name","字母G");  
  56.         list.add(map);  
  57.         map=new HashMap();  
  58.         map.put("img",R.mipmap.h);  
  59.         map.put("name","字母H");  
  60.         list.add(map);  
  61.   
  62.         /* 
  63.         1.simpleAdapter使用的数据源必须继承Map接口 
  64.         2.from参数的意思是指向数据源Map中的键 
  65.         3.to 参数的意思是为布局中的控件Id赋值 
  66.          */  
  67.         SimpleAdapter sa=new SimpleAdapter(this,list,  
  68.                 R.layout.grid_layout,  
  69.                 new String[]{"img","name"},  
  70.                 new int[]{R.id.iv,R.id.tv});  
  71.         gv.setAdapter(sa);  
  72.   
  73.         gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {  
  74.             @Override  
  75.             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {  
  76.                 Map map=(Map)list.get(position);  
  77.                 Toast.makeText(getBaseContext(),""+map.get("name"),Toast.LENGTH_SHORT).show();  
  78.                 Intent intent=new Intent(getBaseContext(),BigActivity.class);  
  79.                 intent.putExtra("img",(int)map.get("img"));  
  80.                 startActivity(intent);  
  81.   
  82.             }  
  83.         });  
  84.   
  85.   
  86.   
  87.   
  88.     }  
  89. }  
setContentView(R.layout.activity_grid_view);程序代码
[html] view plain copy
在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     tools:context="com.example.jreduch7292.GridViewActivity">  
  7.     <GridView  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="match_parent"  
  10.         android:id="@+id/gv"  
  11.         android:numColumns="auto_fit"  
  12.         android:stretchMode="columnWidth"  
  13.         android:columnWidth="100dp"  
  14.         android:horizontalSpacing="5dp"  
  15.         android:verticalSpacing="5dp"  
  16.         android:cacheColorHint="#00000000"  
  17.         android:listSelector="#00000000"  
  18.         android:scrollbars="none"  
  19.   
  20.         ></GridView>  
  21.   
  22.   
  23. </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
在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.   
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="match_parent">  
  7. <ImageView  
  8.     android:layout_width="match_parent"  
  9.     android:layout_height="100dp"  
  10. android:scaleType="centerCrop"  
  11.     android:id="@+id/iv"  
  12.     android:src="@mipmap/ic_launcher"  
  13.     /><!--android:scaleType="centerCrop"等比例缩放-->  
  14.     <TextView  
  15.         android:layout_width="match_parent"  
  16.         android:layout_height="wrap_content"  
  17.         android:id="@+id/tv"  
  18.         android:gravity="center"  
  19.         android:text="测试"  
  20.         />  
  21. </LinearLayout>  
setContentView(R.layout.activity_big);程序代码 放大
[java] view plain copy
在CODE上查看代码片派生到我的代码片
  1. package com.example.jreduch7292;  
  2.   
  3. import android.animation.ObjectAnimator;  
  4. import android.content.Intent;  
  5. import android.os.Bundle;  
  6. import android.support.v7.app.AppCompatActivity;  
  7. import android.view.animation.BounceInterpolator;  
  8.   
  9. import uk.co.senab.photoview.PhotoView;  
  10.   
  11. public class BigActivity extends AppCompatActivity {  
  12. private PhotoView big;  
  13.     @Override  
  14.     protected void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.activity_big);  
  17.         big=(PhotoView)findViewById(R.id.big);  
  18.         Intent intent=getIntent();  
  19.         int imgId=intent.getIntExtra("img",R.mipmap.ic_launcher);  
  20.         big.setImageResource(imgId);  
  21.         //属性动画  
  22.         ObjectAnimator oja=ObjectAnimator.ofFloat(big,"rotation",0,360);  
  23.         oja.setDuration(3000);  
  24.         oja.setRepeatCount(0);  
  25.         //设置插补器  
  26.         oja.setInterpolator(new BounceInterpolator());  
  27.         oja.start();  
  28.     }  
  29. }  
[html] view plain copy
在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     android:paddingBottom="@dimen/activity_vertical_margin"  
  7.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  8.     android:paddingRight="@dimen/activity_horizontal_margin"  
  9.     android:paddingTop="@dimen/activity_vertical_margin"  
  10.     tools:context="com.example.jreduch7292.BigActivity">  
  11. <uk.co.senab.photoview.PhotoView  
  12.     android:layout_width="match_parent"  
  13.     android:layout_height="match_parent"  
  14.     android:id="@+id/big" />  
  15. </RelativeLayout>  

GridViewTextActivityr程序代码

[java] view plain copy
在CODE上查看代码片派生到我的代码片
  1. package com.example.jreduch7292;  
  2.   
  3. import android.support.v7.app.AppCompatActivity;  
  4. import android.os.Bundle;  
  5. import android.widget.GridView;  
  6. import android.widget.SimpleAdapter;  
  7.   
  8. import java.util.ArrayList;  
  9. import java.util.HashMap;  
  10. import java.util.List;  
  11. import java.util.Map;  
  12.   
  13. public class GridViewTextActivityr extends AppCompatActivity {  
  14.     private GridView gv1;  
  15.     @Override  
  16.     protected void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.activity_grid_view_text_activityr);  
  19.             getSupportActionBar().hide();  
  20.             //隐藏ActionBar  
  21. gv1=(GridView)findViewById(R.id.gv1);  
  22.         final List list=new ArrayList();  
  23.         Map map=new HashMap();  
  24.         map.put("name","推荐");  
  25.         list.add(map);  
  26.         map=new HashMap();  
  27.         map.put("name","热点");  
  28.         list.add(map);  
  29.         map=new HashMap();;  
  30.         map.put("name","体育");  
  31.         list.add(map);  
  32.         map=new HashMap();  
  33.         map.put("name","烟台");  
  34.         list.add(map);  
  35.         map=new HashMap();  
  36.         map.put("name","视频");  
  37.         list.add(map);  
  38.         map=new HashMap();  
  39.         map.put("name","汽车");  
  40.         list.add(map);  
  41.         map=new HashMap();  
  42.         map.put("name","订阅");  
  43.         list.add(map);  
  44.         map=new HashMap();  
  45.         map.put("name","社会");  
  46.         list.add(map);  
  47.         map=new HashMap();;  
  48.         map.put("name","财经");  
  49.         list.add(map);  
  50.         map=new HashMap();  
  51.         map.put("name","科技");  
  52.         list.add(map);  
  53.         map=new HashMap();  
  54.         map.put("name","健康");  
  55.         list.add(map);  
  56.         map=new HashMap();  
  57.         map.put("name","军事");  
  58.         list.add(map);  
  59.         map=new HashMap();  
  60.         map.put("name","彩票");  
  61.         list.add(map);  
  62.             map=new HashMap();  
  63.             map.put("name","国际");  
  64.             list.add(map);  
  65.             map=new HashMap();  
  66.             map.put("name","段子");  
  67.             list.add(map);  
  68.         map=new HashMap();  
  69.         map.put("name","科技");  
  70.         list.add(map);  
  71.         map=new HashMap();  
  72.         map.put("name","健康");  
  73.         list.add(map);  
  74.         map=new HashMap();  
  75.         map.put("name","军事");  
  76.         list.add(map);  
  77.         map=new HashMap();  
  78.         map.put("name","彩票");  
  79.         list.add(map);  
  80.         /* 
  81.         1.simpleAdapter使用的数据源必须继承Map接口 
  82.         2.from参数的意思是指向数据源Map中的键 
  83.         3.to 参数的意思是为布局中的控件Id赋值 
  84.          */  
  85.         SimpleAdapter sa=new SimpleAdapter(this,list,  
  86.                 R.layout.grid2_layout,  
  87.                 new String[]{"name"},  
  88.                 new int[]{R.id.tv});  
  89.         gv1.setAdapter(sa);  
  90.     }  
  91. }  
[html] view plain copy
在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.   
  7.     tools:context="com.example.jreduch7292.GridViewTextActivityr">  
  8.     <LinearLayout  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="wrap_content"  
  11.         android:id="@+id/ll"  
  12.         android:orientation="horizontal"  
  13.         android:background="#b3a9a9"  
  14.         >  
  15.         <TextView  
  16.             android:layout_width="wrap_content"  
  17.             android:layout_height="wrap_content"  
  18.             android:text="我的频道"  
  19.             android:textSize="30dp"  
  20.             />  
  21.         <Button  
  22.             android:layout_width="wrap_content"  
  23.             android:layout_height="wrap_content"  
  24.             android:text="编辑"  
  25.             android:textColor="#f70808"  
  26.             android:textSize="25sp"  
  27.             android:layout_marginLeft="50dp"  
  28.             android:background="@drawable/bian"  
  29.             />  
  30.         <ImageView  
  31.             android:layout_width="50dp"  
  32.             android:layout_height="50dp"  
  33.             android:src="@mipmap/fhee"  
  34.             android:layout_marginLeft="20dp"  
  35.             />  
  36.     </LinearLayout>  
  37.     <GridView  
  38.         android:layout_width="match_parent"  
  39.         android:layout_height="match_parent"  
  40.         android:layout_marginTop="10dp"  
  41.         android:id="@+id/gv1"  
  42.         android:layout_below="@+id/ll"  
  43.         android:numColumns="4"  
  44.         android:stretchMode="columnWidth"  
  45.         android:columnWidth="100dp"  
  46.         android:horizontalSpacing="5dp"  
  47.         android:verticalSpacing="5dp"  
  48.         android:cacheColorHint="#00000000"  
  49.         android:listSelector="#00000000"  
  50.         android:scrollbars="none"  
  51.         android:layout_marginLeft="10dp"  
  52.         android:layout_marginRight="10dp"  
  53.   
  54.         >  
  55.     </GridView>  
  56.   
  57. </RelativeLayout>  
[html] view plain copy
在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical" android:layout_width="match_parent"  
  4.     android:layout_height="match_parent">  
  5. <Button  
  6.     android:layout_width="wrap_content"  
  7.     android:layout_height="wrap_content"  
  8.     android:background="@drawable/biankuan"  
  9.     android:id="@+id/tv"  
  10.     android:textColor="@color/red"  
  11.     android:textSize="20dp"  
  12.     />  
  13. </LinearLayout>  
重点重点重点
[java] view plain copy
在CODE上查看代码片派生到我的代码片
  1. package com.example.jreduch7292;  
  2.   
  3. import android.os.Bundle;  
  4. import android.support.v4.view.ViewPager;  
  5. import android.support.v7.app.AppCompatActivity;  
  6. import android.widget.HorizontalScrollView;  
  7. import android.widget.ImageView;  
  8. import android.widget.RadioButton;  
  9. import android.widget.RadioGroup;  
  10. import android.widget.Toast;  
  11.   
  12. import com.example.jreduch7292.adapter.MyViewPagerAdapter;  
  13.   
  14. import java.util.ArrayList;  
  15. import java.util.List;  
  16.   
  17. public class ScrollViewActivity extends AppCompatActivity {  
  18. private RadioGroup rg;  
  19.     private ViewPager vp;  
  20.     private List<ImageView> imgList;  
  21.     private MyViewPagerAdapter mp;  
  22.     private RadioButton rb1,rb2,rb3,rb4,rb5,rb6,rb7,rb8,rb9,rb10;  
  23.     private HorizontalScrollView hs;  
  24.   
  25.     @Override  
  26.     protected void onCreate(Bundle savedInstanceState) {  
  27.         super.onCreate(savedInstanceState);  
  28.         setContentView(R.layout.activity_scroll_view);  
  29.         rb1=(RadioButton) findViewById(R.id.rb1);  
  30.         rb2=(RadioButton) findViewById(R.id.rb2);  
  31.         rb3=(RadioButton) findViewById(R.id.rb3);  
  32.         rb4=(RadioButton) findViewById(R.id.rb4);  
  33.         rb5=(RadioButton) findViewById(R.id.rb5);  
  34.         rb6=(RadioButton) findViewById(R.id.rb6);  
  35.         rb7=(RadioButton) findViewById(R.id.rb7);  
  36.         rb8=(RadioButton) findViewById(R.id.rb8);  
  37.         rb9=(RadioButton) findViewById(R.id.rb9);  
  38.         rb10=(RadioButton) findViewById(R.id.rb10);  
  39.   
  40.   
  41.     hs=(HorizontalScrollView)findViewById(R.id.hs);  
  42.   
  43.         rg=(RadioGroup)findViewById(R.id.rg);  
  44.         vp=(ViewPager)findViewById(R.id.vp);  
  45.         vpInit();  
  46.         rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {  
  47.             @Override  
  48.             public void onCheckedChanged(RadioGroup group, int checkedId) {  
  49.                 if (checkedId==R.id.rb1){  
  50.                     vp.setCurrentItem(0);  
  51.                     Toast.makeText(getBaseContext(),"推荐1",Toast.LENGTH_SHORT).show();  
  52.                 } else if (checkedId==R.id.rb2){  
  53.                     vp.setCurrentItem(1);  
  54.                     Toast.makeText(getBaseContext(),"推荐2",Toast.LENGTH_SHORT).show();  
  55.                 }  
  56.                 else if (checkedId==R.id.rb3){  
  57.                     vp.setCurrentItem(2);  
  58.                     Toast.makeText(getBaseContext(),"推荐3",Toast.LENGTH_SHORT).show();  
  59.                 }else{  
  60.                     switch(checkedId){  
  61.                         case R.id.rb4:  
  62.                             vp.setCurrentItem(3);  
  63.                             Toast.makeText(getBaseContext(),"推荐4",Toast.LENGTH_SHORT).show();  
  64.                             break;  
  65.                         case R.id.rb5:  
  66.                             vp.setCurrentItem(4);  
  67.                             Toast.makeText(getBaseContext(),"推荐5",Toast.LENGTH_SHORT).show();  
  68.                             break;  
  69.                         case R.id.rb6:  
  70.                             Toast.makeText(getBaseContext(),"推荐6",Toast.LENGTH_SHORT).show();  
  71.                             break;  
  72.                         case R.id.rb7:  
  73.                             Toast.makeText(getBaseContext(),"推荐7",Toast.LENGTH_SHORT).show();  
  74.                             break;  
  75.                     }  
  76.                 }  
  77.             }  
  78.         });  
  79.   
  80.     }  
  81.   
  82.     public  void  vpInit(){  
  83.         imgList=new ArrayList<>();  
  84. //        HashMap map=new HashMap();  
  85. //        //Map map=new HashMap();  
  86. //        map.put("name",R.mipmap.eeo);  
  87. //        imgList.add(map);  
  88. //        SimpleAdapter sa=new SimpleAdapter();  
  89.         ImageView iv=new ImageView(this);  
  90.         iv.setImageResource(R.mipmap.zyfzyf);  
  91.         imgList.add(iv);  
  92.         iv=new  ImageView(this);  
  93.         iv.setImageResource(R.mipmap.eet);  
  94.         imgList.add(iv);  
  95.         iv=new  ImageView(this);  
  96.         iv.setImageResource(R.mipmap.eer);  
  97.         imgList.add(iv);  
  98.         iv=new  ImageView(this);  
  99.         iv.setImageResource(R.mipmap.eep);  
  100.         imgList.add(iv);  
  101.         iv=new  ImageView(this);  
  102.         iv.setImageResource(R.mipmap.eeq);  
  103.         imgList.add(iv);  
  104.         iv=new  ImageView(this);  
  105.         iv.setImageResource(R.mipmap.eew);  
  106.         imgList.add(iv);  
  107.         iv=new  ImageView(this);  
  108.         iv.setImageResource(R.mipmap.eex);  
  109.         imgList.add(iv);  
  110.         iv=new  ImageView(this);  
  111.         iv.setImageResource(R.mipmap.eez);  
  112.         imgList.add(iv);  
  113.         iv=new  ImageView(this);  
  114.         iv.setImageResource(R.mipmap.efa);  
  115.         imgList.add(iv);  
  116.         iv=new  ImageView(this);  
  117.         iv.setImageResource(R.mipmap.efb);  
  118.         imgList.add(iv);  
  119.   
  120.         mp=new MyViewPagerAdapter(imgList);  
  121.         vp.setAdapter(mp);  
  122.         vp.setCurrentItem(0);  
  123.         vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {  
  124.             @Override  
  125.             public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {  
  126.   
  127.             }  
  128.   
  129.             @Override  
  130.             public void onPageSelected(int position) {  
  131.        RadioButton rb=(RadioButton) rg.getChildAt(position);  
  132.                 rb.setChecked(true);  
  133.   
  134.             }  
  135.   
  136.             @Override  
  137.             public void onPageScrollStateChanged(int state) {  
  138.   
  139.             }  
  140.         });  
  141.   
  142.     }  
  143.   
  144.   
  145. }  
[html] view plain copy
在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     tools:context="com.example.jreduch7292.ScrollViewActivity">  
  7. <HorizontalScrollView  
  8.     android:layout_width="match_parent"  
  9.     android:layout_height="50dp"  
  10.     android:scrollbars="none"  
  11.     android:id="@+id/hs"  
  12.     >  
  13. <RadioGroup  
  14.     android:layout_width="match_parent"  
  15.     android:layout_height="match_parent"  
  16.     android:orientation="horizontal"  
  17.     android:id="@+id/rg">  
  18.     <RadioButton  
  19.         android:layout_width="50dp"  
  20.         android:layout_height="match_parent"  
  21.         android:text="推荐1"  
  22.         android:id="@+id/rb1"  
  23.         android:button="@null"  
  24.         android:checked="true"  
  25.         android:textColor="@color/rdbt_text_color"  
  26.         android:gravity="center"  
  27.         />  
  28.     <RadioButton  
  29.         android:layout_width="50dp"  
  30.         android:layout_height="match_parent"  
  31.         android:text="推荐2"  
  32.         android:id="@+id/rb2"  
  33.         android:button="@null"  
  34.         android:gravity="center"  
  35.         android:textColor="@color/rdbt_text_color"  
  36.         />  
  37.     <RadioButton  
  38.         android:layout_width="50dp"  
  39.         android:layout_height="match_parent"  
  40.         android:text="推荐3"  
  41.         android:id="@+id/rb3"  
  42.         android:button="@null"  
  43.         android:gravity="center"  
  44.         android:textColor="@color/rdbt_text_color"  
  45.         />  
  46.     <RadioButton  
  47.         android:layout_width="50dp"  
  48.         android:layout_height="match_parent"  
  49.         android:text="推荐4"  
  50.         android:id="@+id/rb4"  
  51.         android:button="@null"  
  52.         android:gravity="center"  
  53.         android:textColor="@color/rdbt_text_color"  
  54.         />  
  55.     <RadioButton  
  56.         android:layout_width="50dp"  
  57.         android:layout_height="match_parent"  
  58.         android:text="推荐5"  
  59.         android:id="@+id/rb5"  
  60.         android:button="@null"  
  61.         android:gravity="center"  
  62.         android:textColor="@color/rdbt_text_color"  
  63.         />  
  64.     <RadioButton  
  65.         android:layout_width="50dp"  
  66.         android:layout_height="match_parent"  
  67.         android:text="推荐6"  
  68.         android:id="@+id/rb6"  
  69.         android:button="@null"  
  70.         android:textColor="@color/rdbt_text_color"  
  71.         android:gravity="center"  
  72.         />  
  73.     <RadioButton  
  74.         android:layout_width="50dp"  
  75.         android:layout_height="match_parent"  
  76.         android:text="推荐7"  
  77.         android:id="@+id/rb7"  
  78.         android:textColor="@color/rdbt_text_color"  
  79.         android:button="@null"  
  80.         android:gravity="center"  
  81.         />  
  82.     <RadioButton  
  83.         android:layout_width="50dp"  
  84.         android:layout_height="match_parent"  
  85.         android:text="推荐8"  
  86.         android:id="@+id/rb8"  
  87.         android:button="@null"  
  88.         android:textColor="@color/rdbt_text_color"  
  89.         android:gravity="center"  
  90.         />  
  91.     <RadioButton  
  92.         android:layout_width="50dp"  
  93.         android:layout_height="match_parent"  
  94.         android:text="推荐9"  
  95.         android:id="@+id/rb9"  
  96.         android:button="@null"  
  97.         android:textColor="@color/rdbt_text_color"  
  98.         android:gravity="center"  
  99.         />  
  100.     <RadioButton  
  101.         android:layout_width="50dp"  
  102.         android:layout_height="match_parent"  
  103.         android:text="推荐10"  
  104.         android:id="@+id/rb10"  
  105.         android:textColor="@color/rdbt_text_color"  
  106.         android:button="@null"  
  107.         android:gravity="center"  
  108.         />  
  109.   
  110. </RadioGroup>  
  111. </HorizontalScrollView>  
  112.     <android.support.v4.view.ViewPager  
  113.         android:layout_width="match_parent"  
  114.         android:layout_height="match_parent"  
  115.         android:id="@+id/vp"  
  116.         android:background="#efc60f"  
  117.         android:layout_below="@+id/hs"  
  118.         >  
  119.   
  120.     </android.support.v4.view.ViewPager>  
  121. </RelativeLayout>  
SpinnerActivity 程序代码
[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. package com.example.jreduch7292;  
  2.   
  3. import android.os.Bundle;  
  4. import android.support.v7.app.AppCompatActivity;  
  5. import android.view.View;  
  6. import android.widget.AdapterView;  
  7. import android.widget.ArrayAdapter;  
  8. import android.widget.Spinner;  
  9. import android.widget.Toast;  
  10.   
  11. import java.util.ArrayList;  
  12. import java.util.List;  
  13.   
  14. public class SpinnerActivity extends AppCompatActivity {  
  15. private Spinner sp;  
  16.     @Override  
  17.     protected void onCreate(Bundle savedInstanceState) {  
  18.         super.onCreate(savedInstanceState);  
  19.         setContentView(R.layout.activity_spinner);  
  20.         sp=(Spinner)findViewById(R.id.sp);  
  21.         List cityList=new ArrayList();  
  22.         cityList.add("北京");  
  23.         cityList.add("上海");  
  24.         cityList.add("广州");  
  25.         //最简单的适配器只能显示一行文字  
  26.         ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_spinner_item,  
  27.                 android.R.id.text1,cityList);  
  28.                 sp.setAdapter(aa);  
  29.         sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {  
  30.             @Override  
  31.             public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {  
  32.                 Toast.makeText(getBaseContext(),sp.getSelectedItem().toString(),Toast.LENGTH_SHORT).show();  
  33.             }  
  34.   
  35.             @Override  
  36.             public void onNothingSelected(AdapterView<?> parent) {  
  37.   
  38.             }  
  39.         });  
  40.   
  41.     }  
  42. }  

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.   
  7.     tools:context="com.example.jreduch7292.SpinnerActivity">  
  8.     <Spinner  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="wrap_content"  
  11.         android:id="@+id/sp1"  
  12.         android:entries="@array/city"  
  13.         ></Spinner>  
  14.     <Spinner  
  15.         android:layout_width="match_parent"  
  16.         android:layout_height="wrap_content"  
  17.         android:id="@+id/sp"  
  18.         android:layout_below="@+id/sp1"  
  19.         android:layout_alignParentStart="true"  
  20.         ></Spinner>  
  21. </RelativeLayout>  
</string><string-array name="city">    <item>烟台</item>    <item>济南</item>    <item>青岛</item></string-array>


0 0