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

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

下载地址:点击下载

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

侧滑菜单的lib  点击下载

 package com.lixu.testjsonall;

 import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity;
import com.lixu.testjsonall.fragments.Cehua_Fragment;
import com.lixu.testjsonall.fragments.Fragment_one;
import com.lixu.testjsonall.fragments.Fragment_tiyuxinwen;
import com.lixu.testjsonall.fragments.Fragment_yulexinwen;
import android.os.Bundle;
import android.view.Window; // 实现三个Fragment的接口类来实现回调
public class MainActivity extends SlidingActivity implements Cehua_Fragment.SetonCehuaFragmentClickListener,
Fragment_one.SetonFragmentOneClickListener, Fragment_tiyuxinwen.SetonFragmentTiyuxinwenClickListener,
Fragment_yulexinwen.SetonFragmentYulexinwenClickListener { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); getFragmentManager().beginTransaction().add(R.id.main_framelayout, Fragment_one.newFragment()).commit();
// 设置滑出菜单为demo中转样式
setBehindContentView(R.layout.demo);
// 将中转demo布局替换为自定义滑出菜单样式
getFragmentManager().beginTransaction().add(R.id.demo, Cehua_Fragment.newFragment()).commit();
// 获取菜单滑出菜单实例
SlidingMenu slidingMenu = getSlidingMenu();
// 设置滑出菜单的停止宽度
slidingMenu.setBehindOffsetRes(R.dimen.weight); } @Override
public void loadxinwen() {
getFragmentManager().beginTransaction().replace(R.id.main_framelayout, Fragment_one.newFragment()).commit();
// 添加界面后关闭侧滑按钮框
toggle();
} @Override
public void loadyulexinwen() {
getFragmentManager().beginTransaction().replace(R.id.main_framelayout, Fragment_yulexinwen.newFragment())
.commit();
toggle();
} @Override
public void loadtiyuxinwen() {
getFragmentManager().beginTransaction().replace(R.id.main_framelayout, Fragment_tiyuxinwen.newFragment())
.commit();
toggle();
} @Override
public void back() {
toggle(); } }
 package com.lixu.testjsonall.fragments;

 import com.lixu.testjsonall.R;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup; public class Cehua_Fragment extends Fragment {
// 设置回调机制
private SetonCehuaFragmentClickListener mSetonCehuaFragmentClickListener; public interface SetonCehuaFragmentClickListener {
void loadxinwen(); void loadyulexinwen(); void loadtiyuxinwen();
} @Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof SetonCehuaFragmentClickListener) {
mSetonCehuaFragmentClickListener = (SetonCehuaFragmentClickListener) activity;
} else {
throw new RuntimeException(activity.toString() + " must implement 接口");
}
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.cehua_menu, null);
return view;
} @Override
public void onActivityCreated(Bundle savedInstanceState) {
getView().findViewById(R.id.monixinweijiem).setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
mSetonCehuaFragmentClickListener.loadxinwen();
}
});
getView().findViewById(R.id.yulexinwen).setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
mSetonCehuaFragmentClickListener.loadyulexinwen();
}
});
getView().findViewById(R.id.tiyuxinwen).setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
mSetonCehuaFragmentClickListener.loadtiyuxinwen();
}
}); super.onActivityCreated(savedInstanceState);
} public static Cehua_Fragment newFragment() {
Cehua_Fragment f = new Cehua_Fragment();
return f;
}
}
 package com.lixu.testjsonall.fragments;

 import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.google.gson.Gson;
import com.lixu.testjsonall.R;
import com.lixu.testjsonall.json_info.Info;
import com.lixu.testjsonall.json_info.Infoall;
import com.lixu.testjsonall.json_info.MerchantKey;
import com.lixu.testjsonall.untils.Untils;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.TextHttpResponseHandler;
import com.scxh.slider.library.SliderLayout;
import com.scxh.slider.library.SliderTypes.BaseSliderView;
import com.scxh.slider.library.SliderTypes.TextSliderView;
import com.squareup.picasso.Picasso;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import cz.msebera.android.httpclient.Header;
import me.maxwin.view.XListView;
import me.maxwin.view.XListView.IXListViewListener; public class Fragment_one extends Fragment {
private String net_url = "http://192.168.1.124:8080/json/around";
private MyAdapter mMyAdapter;
private ProgressBar mProgressBar;
private SliderLayout mSliderLayout;
private XListView lv;
// 两种布局指针
private static final int TYPE_ONE = 0;
private static final int TYPE_TWO = 1; // 设置回调机制
private SetonFragmentOneClickListener mSetonFragmentOneClickListener; public interface SetonFragmentOneClickListener {
void back(); } @Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof SetonFragmentOneClickListener) {
mSetonFragmentOneClickListener = (SetonFragmentOneClickListener) activity;
} else {
throw new RuntimeException(activity.toString() + " must implement 接口");
}
} public static Fragment newFragment() {
Fragment_one f = new Fragment_one();
return f;
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, null);
return view;
} @Override
public void onActivityCreated(Bundle savedInstanceState) {
lv = (XListView) getView().findViewById(R.id.xlv);
mProgressBar = (ProgressBar) getView().findViewById(R.id.progressbar);
// 找到返回图片按钮 通过回调机制点击设置返回
getView().findViewById(R.id.fanhui).setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
mSetonFragmentOneClickListener.back(); }
}); mMyAdapter = new MyAdapter(getActivity(), -1); View view = LayoutInflater.from(getActivity()).inflate(R.layout.listhead, null);
mSliderLayout = (SliderLayout) view.findViewById(R.id.sliderlayout);
// 将图片坐标点移动到布局右下角
mSliderLayout.setPresetIndicator(SliderLayout.PresetIndicators.Right_Bottom);
// 添加到listview头部
lv.addHeaderView(view); // 遍历hashmap的方法
HashMap<String, String> map = Untils.getData();
for (String n : map.keySet()) {
String key = n;
String txt = map.get(key);
TextSliderView tsv = new TextSliderView(getActivity());
tsv.description(key);
tsv.image(txt); // 将滚动图片根据边框大小居中按正常图片剪切显示
tsv.setScaleType(BaseSliderView.ScaleType.CenterCrop);
mSliderLayout.addSlider(tsv);
} // 数据加载前显示进度转动条
lv.setEmptyView(mProgressBar);
lv.setAdapter(mMyAdapter);
// 初始获取数据
GetAsynchttpdata();
// 设置上拉刷新
lv.setPullLoadEnable(true);
lv.setXListViewListener(new IXListViewListener() { @Override
public void onRefresh() {
// 上拉获取数据
GetAsynchttpdata();
// 设置刷新时间
lv.setRefreshTime(Untils.formatTimeInMillis(System.currentTimeMillis()));
} @Override
public void onLoadMore() {
// 下拉获取数据
GetAsynchttpdata();
}
});
super.onActivityCreated(savedInstanceState);
} // 第三方获取网络数据类
private void GetAsynchttpdata() {
AsyncHttpClient ahc = new AsyncHttpClient();
ahc.get(net_url, new TextHttpResponseHandler() {
// 通过网络地址解析Json数据成String类型
@Override
public void onFailure(int arg0, Header[] arg1, String arg2, Throwable arg3) {
Toast.makeText(getActivity(), "错误!", 0).show(); } @Override
public void onSuccess(int arg0, Header[] arg1, String arg2) {
// 从字符串中解析json文件
Gson gson = new Gson();
Infoall infoall = gson.fromJson(arg2, Infoall.class);
Info info = infoall.getInfo();
List<MerchantKey> mMerchantKey = info.getMerchantKey();
mMyAdapter.setList(mMerchantKey);
// 刷新完毕后停止上拉和下拉刷新图标显示
lv.stopRefresh();
lv.stopLoadMore(); }
}); } private class MyAdapter extends ArrayAdapter { private LayoutInflater flater;
private List<MerchantKey> data = new ArrayList<MerchantKey>();
private Context context; public MyAdapter(Context context, int resource) {
super(context, resource);
this.context = context;
flater = LayoutInflater.from(context);
} public void setList(List<MerchantKey> data) {
this.data = data;
mMyAdapter.notifyDataSetChanged();
} // 第一种布局
public View getViewOne(int position, View convertView, ViewGroup parent) { Viewdata mviewdata = null;
if (convertView == null) {
// 一级优化,view可以复用缓存
mviewdata = new Viewdata();
convertView = flater.inflate(R.layout.list, null);
mviewdata.biaoti = (TextView) convertView.findViewById(R.id.list_name_txt);
mviewdata.biaoti2 = (TextView) convertView.findViewById(R.id.list_coupe_txt);
mviewdata.dizhi = (TextView) convertView.findViewById(R.id.list_location_txt);
mviewdata.juli = (TextView) convertView.findViewById(R.id.list_distance_txt);
mviewdata.jpg = (ImageView) convertView.findViewById(R.id.list_icon_img);
mviewdata.tuan = (ImageView) convertView.findViewById(R.id.list_group_img);
mviewdata.quan = (ImageView) convertView.findViewById(R.id.list_ticket_img);
mviewdata.ka = (ImageView) convertView.findViewById(R.id.list_card_img);
convertView.setTag(mviewdata);
}
// 二级优化 ,只找到一次控件,不会每次都通过R文件找到控件
mviewdata = (Viewdata) convertView.getTag();
mviewdata.biaoti.setText(data.get(position).getName());
mviewdata.biaoti2.setText(data.get(position).getCoupon());
mviewdata.dizhi.setText(data.get(position).getLocation());
mviewdata.juli.setText(data.get(position).getDistance());
Picasso.with(context).load(data.get(position).getPicUrl()).into(mviewdata.jpg); if (data.get(position).getGroupType().equals("YES")) {
mviewdata.tuan.setVisibility(View.VISIBLE);
} else {
mviewdata.tuan.setVisibility(View.GONE);
}
if (data.get(position).getCardType().equals("YES")) {
mviewdata.ka.setVisibility(View.VISIBLE);
} else {
mviewdata.ka.setVisibility(View.GONE);
}
if (data.get(position).getCouponType().equals("YES")) {
mviewdata.quan.setVisibility(View.VISIBLE);
} else {
mviewdata.quan.setVisibility(View.GONE);
} return convertView; } // 第二种布局
public View getViewTwo(int position, View convertView, ViewGroup parent) { Viewdata2 mviewdata2 = null;
if (convertView == null) {
// 一级优化,view可以复用缓存
mviewdata2 = new Viewdata2();
convertView = flater.inflate(R.layout.list2, null);
mviewdata2.biaoti2 = (TextView) convertView.findViewById(R.id.list_name_txt2);
mviewdata2.biaoti22 = (TextView) convertView.findViewById(R.id.list_coupe_txt2);
mviewdata2.juli2 = (TextView) convertView.findViewById(R.id.list_distance2_txt);
mviewdata2.jpg2 = (ImageView) convertView.findViewById(R.id.list_icon_img2);
convertView.setTag(mviewdata2);
}
// 二级优化 ,只找到一次控件,不会每次都通过R文件找到控件
mviewdata2 = (Viewdata2) convertView.getTag();
mviewdata2.biaoti2.setText(data.get(position).getName());
mviewdata2.biaoti22.setText(data.get(position).getCoupon());
mviewdata2.juli2.setText(data.get(position).getDistance());
Picasso.with(context).load(data.get(position).getPicUrl()).into(mviewdata2.jpg2); return convertView; } // 控件类
private class Viewdata {
TextView biaoti;
TextView biaoti2;
TextView dizhi;
TextView juli;
ImageView jpg;
ImageView tuan;
ImageView quan;
ImageView ka; } // 第二个布局的控件类
private class Viewdata2 {
TextView biaoti2;
TextView biaoti22;
TextView juli2;
ImageView jpg2; } @Override
public View getView(int position, View convertView, ViewGroup parent) {
if (getItemViewType(position) == TYPE_ONE) {
return getViewOne(position, convertView, parent);
} else {
return getViewTwo(position, convertView, parent);
}
} @Override
public int getItemViewType(int position) {
// 设置对大小写不敏感 --equalsIgnoreCase
if (data.get(position).getCouponType().equalsIgnoreCase("YES")) {
return TYPE_ONE; } else {
return TYPE_TWO;
} } // 获取返回view的两种类型 不写这个方法容易报错误。。
@Override
public int getViewTypeCount() {
return 2;
} @Override
public int getCount() { return data.size();
} } // 程序退出时销毁
@Override
public void onDestroy() {
super.onDestroy();
if (mSliderLayout != null) {
mSliderLayout.stopAutoCycle();
mSliderLayout = null;
}
} }
 package com.lixu.testjsonall.fragments;

 import com.lixu.testjsonall.R;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup; public class Fragment_tiyuxinwen extends Fragment {
// 设置回调机制
private SetonFragmentTiyuxinwenClickListener mSetonFragmentTiyuxinwenClickListener; public interface SetonFragmentTiyuxinwenClickListener {
void back(); } @Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof SetonFragmentTiyuxinwenClickListener) {
mSetonFragmentTiyuxinwenClickListener = (SetonFragmentTiyuxinwenClickListener) activity;
} else {
throw new RuntimeException(activity.toString() + " must implement 接口");
}
} public static Fragment newFragment() {
Fragment_tiyuxinwen f = new Fragment_tiyuxinwen();
return f;
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.yulexinwen, null);
} @Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getView().findViewById(R.id.fanhui).setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
mSetonFragmentTiyuxinwenClickListener.back(); }
});
} }
 package com.lixu.testjsonall.fragments;

 import com.lixu.testjsonall.R;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener; public class Fragment_yulexinwen extends Fragment {
// 设置回调机制
private SetonFragmentYulexinwenClickListener mSetonFragmentYulexinwenClickListener; public interface SetonFragmentYulexinwenClickListener {
void back(); } @Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof SetonFragmentYulexinwenClickListener) {
mSetonFragmentYulexinwenClickListener = (SetonFragmentYulexinwenClickListener) activity;
} else {
throw new RuntimeException(activity.toString() + " must implement 接口");
}
} public static Fragment newFragment() {
Fragment_yulexinwen f = new Fragment_yulexinwen();
return f;
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.tiyuxinwen, null);
} @Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getView().findViewById(R.id.fanhui).setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
mSetonFragmentYulexinwenClickListener.back(); }
});
} }
 package com.lixu.testjsonall.json_info;

 import java.util.List;

 public class Info {
private List<MerchantKey> merchantKey; public List<MerchantKey> getMerchantKey() {
return merchantKey;
} public void setMerchantKey(List<MerchantKey> merchantKey) {
this.merchantKey = merchantKey;
} }
 package com.lixu.testjsonall.json_info;

 public class Infoall {

     private Info info;

     public Info getInfo() {
return info;
} public void setInfo(Info info) {
this.info = info;
} }
 package com.lixu.testjsonall.json_info;

 public class MerchantKey {
private String name;
private String coupon;
private String location;
private String distance;
private String picUrl;
private String couponType;
private String cardType;
private String groupType; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getCoupon() {
return coupon;
} public void setCoupon(String coupon) {
this.coupon = coupon;
} public String getLocation() {
return location;
} public void setLocation(String location) {
this.location = location;
} public String getDistance() {
return distance;
} public void setDistance(String distance) {
this.distance = distance;
} public String getPicUrl() {
return picUrl;
} public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
} public String getCouponType() {
return couponType;
} public void setCouponType(String couponType) {
this.couponType = couponType;
} public String getCardType() {
return cardType;
} public void setCardType(String cardType) {
this.cardType = cardType;
} public String getGroupType() {
return groupType;
} public void setGroupType(String groupType) {
this.groupType = groupType;
} }
 package com.lixu.testjsonall.untils;

 import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap; public class Untils {
public static String formatTimeInMillis(long timeInMillis) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timeInMillis);
Date date = cal.getTime();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String fmt = dateFormat.format(date); return fmt;
} // 头部数据类
public static HashMap<String, String> getData() {
HashMap<String, String> http_url_maps = new HashMap<String, String>();
http_url_maps.put("天津爆炸", "http://img.my.csdn.net/uploads/201407/26/1406383291_6518.jpg");
http_url_maps.put("四川乐山犍为发生4.2级地震", "http://img.my.csdn.net/uploads/201407/26/1406383290_9329.jpg");
http_url_maps.put("成都重度雾霾", "http://img.my.csdn.net/uploads/201407/26/1406383290_1042.jpg");
http_url_maps.put("苹果公司何去何从?", "http://img.my.csdn.net/uploads/201407/26/1406383275_3977.jpg"); return http_url_maps;
}
}

xml布局:

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_framelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.lixu.testjsonall.MainActivity" > </FrameLayout>
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" > <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="选择您要的项目"
android:textColor="#03A9F4"
android:textSize="25sp" /> <Button
android:id="@+id/monixinweijiem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="模拟新闻界面" /> <Button
android:id="@+id/yulexinwen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="娱乐新闻" /> <Button
android:id="@+id/tiyuxinwen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="体育新闻" /> </LinearLayout>
 <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/demo"
android:layout_width="match_parent"
android:layout_height="match_parent" > </FrameLayout>
 <LinearLayout 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:orientation="vertical"
tools:context="com.lixu.testjsonall.MainActivity" > <include layout="@layout/title_layout" /> <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" > <me.maxwin.view.XListView
android:id="@+id/xlv"
android:layout_width="match_parent"
android:layout_height="match_parent" /> <ProgressBar
android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout> </LinearLayout>
 <?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/white" > <ImageView
android:id="@+id/list_icon_img"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_launcher" /> <TextView
android:id="@+id/list_name_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/list_icon_img"
android:singleLine="true"
android:text="瑞庭竹岛酒店"
android:textColor="@android:color/background_dark"
android:textSize="16sp" /> <TextView
android:id="@+id/list_coupe_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/list_name_txt"
android:layout_toRightOf="@id/list_icon_img"
android:singleLine="true"
android:text="网上预定入住可享返现优惠"
android:textColor="@android:color/holo_red_dark"
android:textSize="14sp" /> <TextView
android:id="@+id/list_distance_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:drawableLeft="@drawable/info_map"
android:text="2.0k"
android:textColor="@android:color/tab_indicator_text"
android:textSize="14sp" /> <TextView
android:id="@+id/list_location_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/list_distance_txt"
android:layout_toRightOf="@id/list_icon_img"
android:singleLine="true"
android:text="四川省成都市高新区老成仁路8号成都市高新区老成都市高新区老成都市高新区老成都市高新区老"
android:textColor="@android:color/tab_indicator_text"
android:textSize="14sp" /> <RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" > <ImageView
android:id="@+id/list_card_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/near_card" /> <ImageView
android:id="@+id/list_group_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/list_card_img"
android:src="@drawable/near_group" /> <ImageView
android:id="@+id/list_ticket_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/list_group_img"
android:src="@drawable/near_ticket" />
</RelativeLayout> </RelativeLayout>
 <?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@android:color/white" > <TextView
android:id="@+id/list_distance2_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:drawableLeft="@drawable/info_map"
android:text="2.0k"
android:textColor="@android:color/tab_indicator_text"
android:textSize="14sp" /> <TextView
android:id="@+id/list_name_txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:singleLine="true"
android:text="瑞庭竹岛酒店"
android:textColor="@android:color/background_dark"
android:textSize="16sp" /> <TextView
android:id="@+id/list_coupe_txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/list_name_txt2"
android:singleLine="true"
android:text="网上预定入住可享返现优惠"
android:textColor="@android:color/holo_red_dark"
android:textSize="14sp" /> <ImageView
android:id="@+id/list_icon_img2"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/list_distance2_txt"
android:src="@drawable/ic_launcher" /> </RelativeLayout>
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <com.scxh.slider.library.SliderLayout
android:id="@+id/sliderlayout"
android:layout_width="match_parent"
android:layout_height="150dp" /> </LinearLayout>
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/title_log"> <ImageView
android:id="@+id/fanhui"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:src="@drawable/btn_back" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text=" 我的关注"
android:textSize="25sp" /> </LinearLayout>
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context="com.lixu.testjsonall.MainActivity" > <include layout="@layout/title_layout" /> <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00C853"
android:gravity="center"
android:text="我是体育新闻界面"
android:textColor="#B71C1C"
android:textSize="30sp" /> </LinearLayout>
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <include layout="@layout/title_layout" /> <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f44336"
android:gravity="center"
android:text="我是娱乐新闻界面"
android:textColor="#03A9F4"
android:textSize="30sp" /> </LinearLayout>

运行效果图:

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

上一篇:【Python数据挖掘】决策树、随机森林、Bootsing、


下一篇:python 脚本开发实战-当当亚马逊图书采集器转淘宝数据包