編輯:關於android開發
需要用到的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>
運行效果圖:
ViewPager+GridView實現橫向滑動 仿大眾點評,viewpagergridview先看演示效果: 1 ViewPager類提供了
Android應用程序的啟動流程 Android系統中一個應用程序的主題是由ActivityThread構成的。不過涉及到很多細節如ActivityThread是由誰來創
跨平台開發的兩種方法及其對比,兩種方法為什麼移動應用開發對很多開發人員來說,都是一件令人頭痛的事?這是因為,每種流行的移動平台都具有自身的開發語言、開發工具及其特征。 這
Volley的基本使用,Volley使用本人初學,如有纰缪,望指正~ Volley是Google在2003年的I/O大會上推出的通信框架,結合了Asyn