模拟QQ侧滑控件 实现三种界面切换效果(知识点:回调机制,解析网络json数据,fragment用法等)。

需要用到的lib包 :解析json  gson包,从网络地址解析json数据成String字符串的异步网络解析工具AsyncHttpClient等

下载地址:点击下载

Xlistview 下拉上拉第三方框架  点击下载

侧滑菜单的lib  点击下载

 1 package com.lixu.testjsonall;
 2
 3 import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
 4 import com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity;
 5 import com.lixu.testjsonall.fragments.Cehua_Fragment;
 6 import com.lixu.testjsonall.fragments.Fragment_one;
 7 import com.lixu.testjsonall.fragments.Fragment_tiyuxinwen;
 8 import com.lixu.testjsonall.fragments.Fragment_yulexinwen;
 9 import android.os.Bundle;
10 import android.view.Window;
11
12 // 实现三个Fragment的接口类来实现回调
13 public class MainActivity extends SlidingActivity implements Cehua_Fragment.SetonCehuaFragmentClickListener,
14         Fragment_one.SetonFragmentOneClickListener, Fragment_tiyuxinwen.SetonFragmentTiyuxinwenClickListener,
15         Fragment_yulexinwen.SetonFragmentYulexinwenClickListener {
16
17     @Override
18     public void onCreate(Bundle savedInstanceState) {
19         super.onCreate(savedInstanceState);
20         requestWindowFeature(Window.FEATURE_NO_TITLE);
21         setContentView(R.layout.activity_main);
22
23         getFragmentManager().beginTransaction().add(R.id.main_framelayout, Fragment_one.newFragment()).commit();
24         // 设置滑出菜单为demo中转样式
25         setBehindContentView(R.layout.demo);
26         // 将中转demo布局替换为自定义滑出菜单样式
27         getFragmentManager().beginTransaction().add(R.id.demo, Cehua_Fragment.newFragment()).commit();
28         // 获取菜单滑出菜单实例
29         SlidingMenu slidingMenu = getSlidingMenu();
30         // 设置滑出菜单的停止宽度
31         slidingMenu.setBehindOffsetRes(R.dimen.weight);
32
33     }
34
35     @Override
36     public void loadxinwen() {
37         getFragmentManager().beginTransaction().replace(R.id.main_framelayout, Fragment_one.newFragment()).commit();
38         // 添加界面后关闭侧滑按钮框
39         toggle();
40     }
41
42     @Override
43     public void loadyulexinwen() {
44         getFragmentManager().beginTransaction().replace(R.id.main_framelayout, Fragment_yulexinwen.newFragment())
45                 .commit();
46         toggle();
47     }
48
49     @Override
50     public void loadtiyuxinwen() {
51         getFragmentManager().beginTransaction().replace(R.id.main_framelayout, Fragment_tiyuxinwen.newFragment())
52                 .commit();
53         toggle();
54     }
55
56     @Override
57     public void back() {
58         toggle();
59
60     }
61
62 }
 1 package com.lixu.testjsonall.fragments;
 2
 3 import com.lixu.testjsonall.R;
 4 import android.app.Activity;
 5 import android.app.Fragment;
 6 import android.os.Bundle;
 7 import android.view.LayoutInflater;
 8 import android.view.View;
 9 import android.view.View.OnClickListener;
10 import android.view.ViewGroup;
11
12 public class Cehua_Fragment extends Fragment {
13     // 设置回调机制
14     private SetonCehuaFragmentClickListener mSetonCehuaFragmentClickListener;
15
16     public interface SetonCehuaFragmentClickListener {
17         void loadxinwen();
18
19         void loadyulexinwen();
20
21         void loadtiyuxinwen();
22     }
23
24     @Override
25     public void onAttach(Activity activity) {
26         super.onAttach(activity);
27         if (activity instanceof SetonCehuaFragmentClickListener) {
28             mSetonCehuaFragmentClickListener = (SetonCehuaFragmentClickListener) activity;
29         } else {
30             throw new RuntimeException(activity.toString() + " must implement 接口");
31         }
32     }
33
34     @Override
35     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
36         View view = inflater.inflate(R.layout.cehua_menu, null);
37         return view;
38     }
39
40     @Override
41     public void onActivityCreated(Bundle savedInstanceState) {
42         getView().findViewById(R.id.monixinweijiem).setOnClickListener(new OnClickListener() {
43
44             @Override
45             public void onClick(View v) {
46                 mSetonCehuaFragmentClickListener.loadxinwen();
47             }
48         });
49         getView().findViewById(R.id.yulexinwen).setOnClickListener(new OnClickListener() {
50
51             @Override
52             public void onClick(View v) {
53                 mSetonCehuaFragmentClickListener.loadyulexinwen();
54             }
55         });
56         getView().findViewById(R.id.tiyuxinwen).setOnClickListener(new OnClickListener() {
57
58             @Override
59             public void onClick(View v) {
60                 mSetonCehuaFragmentClickListener.loadtiyuxinwen();
61             }
62         });
63
64         super.onActivityCreated(savedInstanceState);
65     }
66
67     public static Cehua_Fragment newFragment() {
68         Cehua_Fragment f = new Cehua_Fragment();
69         return f;
70     }
71 }
  1 package com.lixu.testjsonall.fragments;
  2
  3 import java.util.ArrayList;
  4 import java.util.HashMap;
  5 import java.util.List;
  6 import com.google.gson.Gson;
  7 import com.lixu.testjsonall.R;
  8 import com.lixu.testjsonall.json_info.Info;
  9 import com.lixu.testjsonall.json_info.Infoall;
 10 import com.lixu.testjsonall.json_info.MerchantKey;
 11 import com.lixu.testjsonall.untils.Untils;
 12 import com.loopj.android.http.AsyncHttpClient;
 13 import com.loopj.android.http.TextHttpResponseHandler;
 14 import com.scxh.slider.library.SliderLayout;
 15 import com.scxh.slider.library.SliderTypes.BaseSliderView;
 16 import com.scxh.slider.library.SliderTypes.TextSliderView;
 17 import com.squareup.picasso.Picasso;
 18 import android.app.Activity;
 19 import android.app.Fragment;
 20 import android.content.Context;
 21 import android.os.Bundle;
 22 import android.view.LayoutInflater;
 23 import android.view.View;
 24 import android.view.View.OnClickListener;
 25 import android.view.ViewGroup;
 26 import android.widget.ArrayAdapter;
 27 import android.widget.ImageView;
 28 import android.widget.ProgressBar;
 29 import android.widget.TextView;
 30 import android.widget.Toast;
 31 import cz.msebera.android.httpclient.Header;
 32 import me.maxwin.view.XListView;
 33 import me.maxwin.view.XListView.IXListViewListener;
 34
 35 public class Fragment_one extends Fragment {
 36     private String net_url = "http://192.168.1.124:8080/json/around";
 37     private MyAdapter mMyAdapter;
 38     private ProgressBar mProgressBar;
 39     private SliderLayout mSliderLayout;
 40     private XListView lv;
 41     // 两种布局指针
 42     private static final int TYPE_ONE = 0;
 43     private static final int TYPE_TWO = 1;
 44
 45     // 设置回调机制
 46     private SetonFragmentOneClickListener mSetonFragmentOneClickListener;
 47
 48     public interface SetonFragmentOneClickListener {
 49         void back();
 50
 51     }
 52
 53     @Override
 54     public void onAttach(Activity activity) {
 55         super.onAttach(activity);
 56         if (activity instanceof SetonFragmentOneClickListener) {
 57             mSetonFragmentOneClickListener = (SetonFragmentOneClickListener) activity;
 58         } else {
 59             throw new RuntimeException(activity.toString() + " must implement 接口");
 60         }
 61     }
 62
 63     public static Fragment newFragment() {
 64         Fragment_one f = new Fragment_one();
 65         return f;
 66     }
 67
 68     @Override
 69     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 70         View view = inflater.inflate(R.layout.fragment_one, null);
 71         return view;
 72     }
 73
 74     @Override
 75     public void onActivityCreated(Bundle savedInstanceState) {
 76         lv = (XListView) getView().findViewById(R.id.xlv);
 77         mProgressBar = (ProgressBar) getView().findViewById(R.id.progressbar);
 78         // 找到返回图片按钮 通过回调机制点击设置返回
 79         getView().findViewById(R.id.fanhui).setOnClickListener(new OnClickListener() {
 80
 81             @Override
 82             public void onClick(View v) {
 83                 mSetonFragmentOneClickListener.back();
 84
 85             }
 86         });
 87
 88         mMyAdapter = new MyAdapter(getActivity(), -1);
 89
 90         View view = LayoutInflater.from(getActivity()).inflate(R.layout.listhead, null);
 91         mSliderLayout = (SliderLayout) view.findViewById(R.id.sliderlayout);
 92         // 将图片坐标点移动到布局右下角
 93         mSliderLayout.setPresetIndicator(SliderLayout.PresetIndicators.Right_Bottom);
 94         // 添加到listview头部
 95         lv.addHeaderView(view);
 96
 97         // 遍历hashmap的方法
 98         HashMap<String, String> map = Untils.getData();
 99         for (String n : map.keySet()) {
100             String key = n;
101             String txt = map.get(key);
102             TextSliderView tsv = new TextSliderView(getActivity());
103             tsv.description(key);
104             tsv.image(txt);
105
106             // 将滚动图片根据边框大小居中按正常图片剪切显示
107             tsv.setScaleType(BaseSliderView.ScaleType.CenterCrop);
108             mSliderLayout.addSlider(tsv);
109         }
110
111         // 数据加载前显示进度转动条
112         lv.setEmptyView(mProgressBar);
113         lv.setAdapter(mMyAdapter);
114         // 初始获取数据
115         GetAsynchttpdata();
116         // 设置上拉刷新
117         lv.setPullLoadEnable(true);
118         lv.setXListViewListener(new IXListViewListener() {
119
120             @Override
121             public void onRefresh() {
122                 // 上拉获取数据
123                 GetAsynchttpdata();
124                 // 设置刷新时间
125                 lv.setRefreshTime(Untils.formatTimeInMillis(System.currentTimeMillis()));
126             }
127
128             @Override
129             public void onLoadMore() {
130                 // 下拉获取数据
131                 GetAsynchttpdata();
132             }
133         });
134         super.onActivityCreated(savedInstanceState);
135     }
136
137     // 第三方获取网络数据类
138     private void GetAsynchttpdata() {
139         AsyncHttpClient ahc = new AsyncHttpClient();
140         ahc.get(net_url, new TextHttpResponseHandler() {
141             // 通过网络地址解析Json数据成String类型
142             @Override
143             public void onFailure(int arg0, Header[] arg1, String arg2, Throwable arg3) {
144                 Toast.makeText(getActivity(), "错误!", 0).show();
145
146             }
147
148             @Override
149             public void onSuccess(int arg0, Header[] arg1, String arg2) {
150                 // 从字符串中解析json文件
151                 Gson gson = new Gson();
152                 Infoall infoall = gson.fromJson(arg2, Infoall.class);
153                 Info info = infoall.getInfo();
154                 List<MerchantKey> mMerchantKey = info.getMerchantKey();
155                 mMyAdapter.setList(mMerchantKey);
156                 // 刷新完毕后停止上拉和下拉刷新图标显示
157                 lv.stopRefresh();
158                 lv.stopLoadMore();
159
160             }
161         });
162
163     }
164
165     private class MyAdapter extends ArrayAdapter {
166
167         private LayoutInflater flater;
168         private List<MerchantKey> data = new ArrayList<MerchantKey>();
169         private Context context;
170
171         public MyAdapter(Context context, int resource) {
172             super(context, resource);
173             this.context = context;
174             flater = LayoutInflater.from(context);
175         }
176
177         public void setList(List<MerchantKey> data) {
178             this.data = data;
179             mMyAdapter.notifyDataSetChanged();
180         }
181
182         // 第一种布局
183         public View getViewOne(int position, View convertView, ViewGroup parent) {
184
185             Viewdata mviewdata = null;
186             if (convertView == null) {
187                 // 一级优化,view可以复用缓存
188                 mviewdata = new Viewdata();
189                 convertView = flater.inflate(R.layout.list, null);
190                 mviewdata.biaoti = (TextView) convertView.findViewById(R.id.list_name_txt);
191                 mviewdata.biaoti2 = (TextView) convertView.findViewById(R.id.list_coupe_txt);
192                 mviewdata.dizhi = (TextView) convertView.findViewById(R.id.list_location_txt);
193                 mviewdata.juli = (TextView) convertView.findViewById(R.id.list_distance_txt);
194                 mviewdata.jpg = (ImageView) convertView.findViewById(R.id.list_icon_img);
195                 mviewdata.tuan = (ImageView) convertView.findViewById(R.id.list_group_img);
196                 mviewdata.quan = (ImageView) convertView.findViewById(R.id.list_ticket_img);
197                 mviewdata.ka = (ImageView) convertView.findViewById(R.id.list_card_img);
198                 convertView.setTag(mviewdata);
199             }
200             // 二级优化 ,只找到一次控件,不会每次都通过R文件找到控件
201             mviewdata = (Viewdata) convertView.getTag();
202             mviewdata.biaoti.setText(data.get(position).getName());
203             mviewdata.biaoti2.setText(data.get(position).getCoupon());
204             mviewdata.dizhi.setText(data.get(position).getLocation());
205             mviewdata.juli.setText(data.get(position).getDistance());
206             Picasso.with(context).load(data.get(position).getPicUrl()).into(mviewdata.jpg);
207
208             if (data.get(position).getGroupType().equals("YES")) {
209                 mviewdata.tuan.setVisibility(View.VISIBLE);
210             } else {
211                 mviewdata.tuan.setVisibility(View.GONE);
212             }
213             if (data.get(position).getCardType().equals("YES")) {
214                 mviewdata.ka.setVisibility(View.VISIBLE);
215             } else {
216                 mviewdata.ka.setVisibility(View.GONE);
217             }
218             if (data.get(position).getCouponType().equals("YES")) {
219                 mviewdata.quan.setVisibility(View.VISIBLE);
220             } else {
221                 mviewdata.quan.setVisibility(View.GONE);
222             }
223
224             return convertView;
225
226         }
227
228         // 第二种布局
229         public View getViewTwo(int position, View convertView, ViewGroup parent) {
230
231             Viewdata2 mviewdata2 = null;
232             if (convertView == null) {
233                 // 一级优化,view可以复用缓存
234                 mviewdata2 = new Viewdata2();
235                 convertView = flater.inflate(R.layout.list2, null);
236                 mviewdata2.biaoti2 = (TextView) convertView.findViewById(R.id.list_name_txt2);
237                 mviewdata2.biaoti22 = (TextView) convertView.findViewById(R.id.list_coupe_txt2);
238                 mviewdata2.juli2 = (TextView) convertView.findViewById(R.id.list_distance2_txt);
239                 mviewdata2.jpg2 = (ImageView) convertView.findViewById(R.id.list_icon_img2);
240                 convertView.setTag(mviewdata2);
241             }
242             // 二级优化 ,只找到一次控件,不会每次都通过R文件找到控件
243             mviewdata2 = (Viewdata2) convertView.getTag();
244             mviewdata2.biaoti2.setText(data.get(position).getName());
245             mviewdata2.biaoti22.setText(data.get(position).getCoupon());
246             mviewdata2.juli2.setText(data.get(position).getDistance());
247             Picasso.with(context).load(data.get(position).getPicUrl()).into(mviewdata2.jpg2);
248
249             return convertView;
250
251         }
252
253         // 控件类
254         private class Viewdata {
255             TextView biaoti;
256             TextView biaoti2;
257             TextView dizhi;
258             TextView juli;
259             ImageView jpg;
260             ImageView tuan;
261             ImageView quan;
262             ImageView ka;
263
264         }
265
266         // 第二个布局的控件类
267         private class Viewdata2 {
268             TextView biaoti2;
269             TextView biaoti22;
270             TextView juli2;
271             ImageView jpg2;
272
273         }
274
275         @Override
276         public View getView(int position, View convertView, ViewGroup parent) {
277             if (getItemViewType(position) == TYPE_ONE) {
278                 return getViewOne(position, convertView, parent);
279             } else {
280                 return getViewTwo(position, convertView, parent);
281             }
282         }
283
284         @Override
285         public int getItemViewType(int position) {
286             // 设置对大小写不敏感 --equalsIgnoreCase
287             if (data.get(position).getCouponType().equalsIgnoreCase("YES")) {
288                 return TYPE_ONE;
289
290             } else {
291                 return TYPE_TWO;
292             }
293
294         }
295
296         // 获取返回view的两种类型 不写这个方法容易报错误。。
297         @Override
298         public int getViewTypeCount() {
299             return 2;
300         }
301
302         @Override
303         public int getCount() {
304
305             return data.size();
306         }
307
308     }
309
310     // 程序退出时销毁
311     @Override
312     public void onDestroy() {
313         super.onDestroy();
314         if (mSliderLayout != null) {
315             mSliderLayout.stopAutoCycle();
316             mSliderLayout = null;
317         }
318     }
319
320 }
 1 package com.lixu.testjsonall.fragments;
 2
 3 import com.lixu.testjsonall.R;
 4 import android.app.Activity;
 5 import android.app.Fragment;
 6 import android.os.Bundle;
 7 import android.view.LayoutInflater;
 8 import android.view.View;
 9 import android.view.View.OnClickListener;
10 import android.view.ViewGroup;
11
12 public class Fragment_tiyuxinwen extends Fragment {
13     // 设置回调机制
14     private SetonFragmentTiyuxinwenClickListener mSetonFragmentTiyuxinwenClickListener;
15
16     public interface SetonFragmentTiyuxinwenClickListener {
17         void back();
18
19     }
20
21     @Override
22     public void onAttach(Activity activity) {
23         super.onAttach(activity);
24         if (activity instanceof SetonFragmentTiyuxinwenClickListener) {
25             mSetonFragmentTiyuxinwenClickListener = (SetonFragmentTiyuxinwenClickListener) activity;
26         } else {
27             throw new RuntimeException(activity.toString() + " must implement 接口");
28         }
29     }
30
31     public static Fragment newFragment() {
32         Fragment_tiyuxinwen f = new Fragment_tiyuxinwen();
33         return f;
34     }
35
36     @Override
37     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
38         return inflater.inflate(R.layout.yulexinwen, null);
39     }
40
41     @Override
42     public void onActivityCreated(Bundle savedInstanceState) {
43         super.onActivityCreated(savedInstanceState);
44         getView().findViewById(R.id.fanhui).setOnClickListener(new OnClickListener() {
45
46             @Override
47             public void onClick(View v) {
48                 mSetonFragmentTiyuxinwenClickListener.back();
49
50             }
51         });
52     }
53
54 }
 1 package com.lixu.testjsonall.fragments;
 2
 3 import com.lixu.testjsonall.R;
 4 import android.app.Activity;
 5 import android.app.Fragment;
 6 import android.os.Bundle;
 7 import android.view.LayoutInflater;
 8 import android.view.View;
 9 import android.view.ViewGroup;
10 import android.view.View.OnClickListener;
11
12 public class Fragment_yulexinwen extends Fragment {
13     // 设置回调机制
14     private SetonFragmentYulexinwenClickListener mSetonFragmentYulexinwenClickListener;
15
16     public interface SetonFragmentYulexinwenClickListener {
17         void back();
18
19     }
20
21     @Override
22     public void onAttach(Activity activity) {
23         super.onAttach(activity);
24         if (activity instanceof SetonFragmentYulexinwenClickListener) {
25             mSetonFragmentYulexinwenClickListener = (SetonFragmentYulexinwenClickListener) activity;
26         } else {
27             throw new RuntimeException(activity.toString() + " must implement 接口");
28         }
29     }
30
31     public static Fragment newFragment() {
32         Fragment_yulexinwen f = new Fragment_yulexinwen();
33         return f;
34     }
35
36     @Override
37     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
38         return inflater.inflate(R.layout.tiyuxinwen, null);
39     }
40
41     @Override
42     public void onActivityCreated(Bundle savedInstanceState) {
43         super.onActivityCreated(savedInstanceState);
44         getView().findViewById(R.id.fanhui).setOnClickListener(new OnClickListener() {
45
46             @Override
47             public void onClick(View v) {
48                 mSetonFragmentYulexinwenClickListener.back();
49
50             }
51         });
52     }
53
54 }
 1 package com.lixu.testjsonall.json_info;
 2
 3 import java.util.List;
 4
 5 public class Info {
 6     private List<MerchantKey> merchantKey;
 7
 8     public List<MerchantKey> getMerchantKey() {
 9         return merchantKey;
10     }
11
12     public void setMerchantKey(List<MerchantKey> merchantKey) {
13         this.merchantKey = merchantKey;
14     }
15
16 }
 1 package com.lixu.testjsonall.json_info;
 2
 3 public class Infoall {
 4
 5     private Info info;
 6
 7     public Info getInfo() {
 8         return info;
 9     }
10
11     public void setInfo(Info info) {
12         this.info = info;
13     }
14
15 }
 1 package com.lixu.testjsonall.json_info;
 2
 3 public class MerchantKey {
 4     private String name;
 5     private String coupon;
 6     private String location;
 7     private String distance;
 8     private String picUrl;
 9     private String couponType;
10     private String cardType;
11     private String groupType;
12
13     public String getName() {
14         return name;
15     }
16
17     public void setName(String name) {
18         this.name = name;
19     }
20
21     public String getCoupon() {
22         return coupon;
23     }
24
25     public void setCoupon(String coupon) {
26         this.coupon = coupon;
27     }
28
29     public String getLocation() {
30         return location;
31     }
32
33     public void setLocation(String location) {
34         this.location = location;
35     }
36
37     public String getDistance() {
38         return distance;
39     }
40
41     public void setDistance(String distance) {
42         this.distance = distance;
43     }
44
45     public String getPicUrl() {
46         return picUrl;
47     }
48
49     public void setPicUrl(String picUrl) {
50         this.picUrl = picUrl;
51     }
52
53     public String getCouponType() {
54         return couponType;
55     }
56
57     public void setCouponType(String couponType) {
58         this.couponType = couponType;
59     }
60
61     public String getCardType() {
62         return cardType;
63     }
64
65     public void setCardType(String cardType) {
66         this.cardType = cardType;
67     }
68
69     public String getGroupType() {
70         return groupType;
71     }
72
73     public void setGroupType(String groupType) {
74         this.groupType = groupType;
75     }
76
77 }
 1 package com.lixu.testjsonall.untils;
 2
 3 import java.text.SimpleDateFormat;
 4 import java.util.Calendar;
 5 import java.util.Date;
 6 import java.util.HashMap;
 7
 8 public class Untils {
 9     public static String formatTimeInMillis(long timeInMillis) {
10         Calendar cal = Calendar.getInstance();
11         cal.setTimeInMillis(timeInMillis);
12         Date date = cal.getTime();
13         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
14         String fmt = dateFormat.format(date);
15
16         return fmt;
17     }
18
19     // 头部数据类
20     public static HashMap<String, String> getData() {
21         HashMap<String, String> http_url_maps = new HashMap<String, String>();
22         http_url_maps.put("天津爆炸", "http://img.my.csdn.net/uploads/201407/26/1406383291_6518.jpg");
23         http_url_maps.put("四川乐山犍为发生4.2级地震", "http://img.my.csdn.net/uploads/201407/26/1406383290_9329.jpg");
24         http_url_maps.put("成都重度雾霾", "http://img.my.csdn.net/uploads/201407/26/1406383290_1042.jpg");
25         http_url_maps.put("苹果公司何去何从?", "http://img.my.csdn.net/uploads/201407/26/1406383275_3977.jpg");
26
27         return http_url_maps;
28     }
29 }

xml布局:

1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2     xmlns:tools="http://schemas.android.com/tools"
3     android:id="@+id/main_framelayout"
4     android:layout_width="match_parent"
5     android:layout_height="match_parent"
6     android:orientation="vertical"
7     tools:context="com.lixu.testjsonall.MainActivity" >
8
9 </FrameLayout>
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:background="@drawable/background"
 6     android:orientation="vertical" >
 7
 8     <TextView
 9         android:layout_width="match_parent"
10         android:layout_height="wrap_content"
11         android:gravity="center"
12         android:text="选择您要的项目"
13         android:textColor="#03A9F4"
14         android:textSize="25sp" />
15
16     <Button
17         android:id="@+id/monixinweijiem"
18         android:layout_width="match_parent"
19         android:layout_height="wrap_content"
20         android:text="模拟新闻界面" />
21
22     <Button
23         android:id="@+id/yulexinwen"
24         android:layout_width="match_parent"
25         android:layout_height="wrap_content"
26         android:text="娱乐新闻" />
27
28     <Button
29         android:id="@+id/tiyuxinwen"
30         android:layout_width="match_parent"
31         android:layout_height="wrap_content"
32         android:text="体育新闻" />
33
34 </LinearLayout>
1 <?xml version="1.0" encoding="utf-8"?>
2 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3     android:id="@+id/demo"
4     android:layout_width="match_parent"
5     android:layout_height="match_parent" >
6
7 </FrameLayout>
 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical"
 6     tools:context="com.lixu.testjsonall.MainActivity" >
 7
 8     <include layout="@layout/title_layout" />
 9
10     <FrameLayout
11         android:layout_width="match_parent"
12         android:layout_height="match_parent" >
13
14         <me.maxwin.view.XListView
15             android:id="@+id/xlv"
16             android:layout_width="match_parent"
17             android:layout_height="match_parent" />
18
19         <ProgressBar
20             android:id="@+id/progressbar"
21             android:layout_width="wrap_content"
22             android:layout_height="wrap_content"
23             android:layout_gravity="center" />
24     </FrameLayout>
25
26 </LinearLayout>
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="80dp"
 5     android:background="@android:color/white" >
 6
 7     <ImageView
 8         android:id="@+id/list_icon_img"
 9         android:layout_width="80dp"
10         android:layout_height="80dp"
11         android:src="@drawable/ic_launcher" />
12
13     <TextView
14         android:id="@+id/list_name_txt"
15         android:layout_width="wrap_content"
16         android:layout_height="wrap_content"
17         android:layout_toRightOf="@id/list_icon_img"
18         android:singleLine="true"
19         android:text="瑞庭竹岛酒店"
20         android:textColor="@android:color/background_dark"
21         android:textSize="16sp" />
22
23     <TextView
24         android:id="@+id/list_coupe_txt"
25         android:layout_width="wrap_content"
26         android:layout_height="wrap_content"
27         android:layout_below="@id/list_name_txt"
28         android:layout_toRightOf="@id/list_icon_img"
29         android:singleLine="true"
30         android:text="网上预定入住可享返现优惠"
31         android:textColor="@android:color/holo_red_dark"
32         android:textSize="14sp" />
33
34     <TextView
35         android:id="@+id/list_distance_txt"
36         android:layout_width="wrap_content"
37         android:layout_height="wrap_content"
38         android:layout_alignParentBottom="true"
39         android:layout_alignParentRight="true"
40         android:layout_marginRight="10dp"
41         android:drawableLeft="@drawable/info_map"
42         android:text="2.0k"
43         android:textColor="@android:color/tab_indicator_text"
44         android:textSize="14sp" />
45
46     <TextView
47         android:id="@+id/list_location_txt"
48         android:layout_width="wrap_content"
49         android:layout_height="wrap_content"
50         android:layout_alignParentBottom="true"
51         android:layout_toLeftOf="@id/list_distance_txt"
52         android:layout_toRightOf="@id/list_icon_img"
53         android:singleLine="true"
54         android:text="四川省成都市高新区老成仁路8号成都市高新区老成都市高新区老成都市高新区老成都市高新区老"
55         android:textColor="@android:color/tab_indicator_text"
56         android:textSize="14sp" />
57
58     <RelativeLayout
59         android:layout_width="wrap_content"
60         android:layout_height="wrap_content"
61         android:layout_alignParentRight="true"
62         android:layout_alignParentTop="true" >
63
64         <ImageView
65             android:id="@+id/list_card_img"
66             android:layout_width="wrap_content"
67             android:layout_height="wrap_content"
68             android:src="@drawable/near_card" />
69
70         <ImageView
71             android:id="@+id/list_group_img"
72             android:layout_width="wrap_content"
73             android:layout_height="wrap_content"
74             android:layout_toRightOf="@id/list_card_img"
75             android:src="@drawable/near_group" />
76
77         <ImageView
78             android:id="@+id/list_ticket_img"
79             android:layout_width="wrap_content"
80             android:layout_height="wrap_content"
81             android:layout_toRightOf="@id/list_group_img"
82             android:src="@drawable/near_ticket" />
83     </RelativeLayout>
84
85 </RelativeLayout>
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="80dp"
 5     android:background="@android:color/white" >
 6
 7     <TextView
 8         android:id="@+id/list_distance2_txt"
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content"
11         android:layout_alignParentBottom="true"
12         android:layout_alignParentRight="true"
13         android:layout_marginRight="10dp"
14         android:drawableLeft="@drawable/info_map"
15         android:text="2.0k"
16         android:textColor="@android:color/tab_indicator_text"
17         android:textSize="14sp" />
18
19
20     <TextView
21         android:id="@+id/list_name_txt2"
22         android:layout_width="wrap_content"
23         android:layout_height="wrap_content"
24         android:layout_alignParentLeft="true"
25         android:layout_alignParentTop="true"
26         android:singleLine="true"
27         android:text="瑞庭竹岛酒店"
28         android:textColor="@android:color/background_dark"
29         android:textSize="16sp" />
30
31     <TextView
32         android:id="@+id/list_coupe_txt2"
33         android:layout_width="wrap_content"
34         android:layout_height="wrap_content"
35         android:layout_alignParentLeft="true"
36         android:layout_below="@+id/list_name_txt2"
37         android:singleLine="true"
38         android:text="网上预定入住可享返现优惠"
39         android:textColor="@android:color/holo_red_dark"
40         android:textSize="14sp" />
41
42
43     <ImageView
44         android:id="@+id/list_icon_img2"
45         android:layout_width="80dp"
46         android:layout_height="80dp"
47         android:layout_alignParentTop="true"
48         android:layout_toLeftOf="@+id/list_distance2_txt"
49         android:src="@drawable/ic_launcher" />
50
51 </RelativeLayout>
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6
 7     <com.scxh.slider.library.SliderLayout
 8         android:id="@+id/sliderlayout"
 9         android:layout_width="match_parent"
10         android:layout_height="150dp" />
11
12 </LinearLayout>
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="wrap_content"
 5     android:orientation="horizontal"
 6     android:background="@drawable/title_log">
 7
 8     <ImageView
 9         android:id="@+id/fanhui"
10         android:layout_width="30dp"
11         android:layout_height="30dp"
12         android:layout_gravity="center"
13         android:src="@drawable/btn_back" />
14
15     <TextView
16         android:layout_width="wrap_content"
17         android:layout_height="wrap_content"
18         android:layout_gravity="center"
19         android:text="    我的关注"
20         android:textSize="25sp" />
21
22 </LinearLayout>
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout 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:orientation="vertical"
 7     tools:context="com.lixu.testjsonall.MainActivity" >
 8
 9     <include layout="@layout/title_layout" />
10
11     <TextView
12         android:layout_width="match_parent"
13         android:layout_height="match_parent"
14         android:background="#00C853"
15         android:gravity="center"
16         android:text="我是体育新闻界面"
17         android:textColor="#B71C1C"
18         android:textSize="30sp" />
19
20 </LinearLayout>
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6
 7     <include layout="@layout/title_layout" />
 8
 9     <TextView
10         android:layout_width="match_parent"
11         android:layout_height="match_parent"
12         android:background="#f44336"
13         android:gravity="center"
14         android:text="我是娱乐新闻界面"
15         android:textColor="#03A9F4"
16         android:textSize="30sp" />
17
18 </LinearLayout>

运行效果图:

时间: 2024-10-01 05:07:57

模拟QQ侧滑控件 实现三种界面切换效果(知识点:回调机制,解析网络json数据,fragment用法等)。的相关文章

Jquery获取服务器端控件的三种方式

一 Jquery获得服务器控件值的方法由于ASP.NET网页运行后,服务器控件会随机生成客户端id,jquery获取时候不太好操作,google了下,总结有以下3种方法: 服务器控件代码:<asp:TextBox ID="txtUserID" runat="server"></asp:TextBox> 1. $("#<%=txtUserID.ClientID%>").val(); 2. $("inpu

多线程总结之旅(112):跨线程调用控件的几种方式

本来是写完线程池就结束多线程总结之旅系列的,但是想想平时在项目中用到线程仅仅不够的,为什么这么说呢?举个例子:我们有一个函数,它的功能就是加载数据,然后绑定到datagridview.现在我们开启一个线程去执行这个函数.结果可想而知,它会报错:提示线程无法访问...之类的话.为什么报错呢?因为你在开启的线程中操作了datagridview控件,也就是你跨线程调用控件了. 那么我们应该怎么跨线程调用控件呢?下面我就把我总结的几种方法奉献给各位. 跨线程调用控件的几种方法: 1.方法一:Contro

JAVASE学习笔记:第十章 SWing常用控件类(三)

11.设置JFrame背景图片 JPanel c= (JPanel)this.getContentPane(); //创建jpanel Toolkit t=Toolkit.getDefaultToolkit(); //背景图片,将panel不透明设置为false c.setOpaque(false); JLabel label = new JLabel(); URL usrc=this.getClass().getClassLoader().getResource("\\images\\bg.J

仿苹果电脑任务栏菜单&amp;&amp;拼图小游戏&amp;&amp;模拟表单控件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

xamarin android——数据绑定到控件(三)

如果当前活动中,只存在一个listview视图,可以借助ListActivity快速的实现一个列表,即当前Activity继承ListActivity.在OnCreate方法中简单的两行代码,就可以创建一个用户列表. string[] items = new string[]{ "列表 1","列表 2","列表 3","列表 4","列表 5","列表 6","列表 7&qu

DevExpress XtraGrid网格控件示例三:获取当前处于编辑状态的值

使用下面的示例代码,以获得当前编辑的值. C# 1 string editingValue; 2 if(gridControl1.KeyboardFocusView.IsEditing) 3 editingValue = gridControl1.KeyboardFocusView.EditingValue.ToString(); DevExpress XtraGrid网格控件示例三:获取当前处于编辑状态的值,布布扣,bubuko.com

窗体或控件的两种拖动方式

第一种 音量调节的示例 #region 音量控制 private Point mouse_offset; private void pictureBox7_MouseDown(object sender, MouseEventArgs e) { mouse_offset = new Point(-e.X, -e.Y);// } private void pictureBox7_MouseMove(object sender, MouseEventArgs e) { ((Control)sende

MFC 访问控件的几种方法

访问控件的方法 控件是一种交互的工具,应用程序需要通过某种方法来访问控件以对其进行查询和设置.访问控件有四种方法: 利用对话框的数据交换功能访问控件.这种方法适用于自动创建的控件.先用ClassWizard为对话框类加入与控件对应的数据成员变量,然后在适当的时侯调用UpdateData,就可以实现对话框和控件的数据交换.这种方法只能交换数据,不能对控件进行全面的查询和设置,而且该方法不是针对某个控件,而是针对所有参与数据交换的控件.另外,对于新型的Win32控件,不能用ClassWizard创建

WPF编程,通过Double Animation同时动态缩放和旋转控件的一种方法。

原文:WPF编程,通过Double Animation同时动态缩放和旋转控件的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/details/87260287 ?1. 可直接调用.需要将控件的名称,缩放的位数,时间等参数传进去.? /// <summary> /// 同时旋转和缩放的动画 /// </summary> /// <param name="element&quo