MainActivity
1 package zhanghaijiao.bawei.com.yuekao_moni; 2 3 import android.graphics.Color; 4 import android.support.v4.app.Fragment; 5 import android.support.v4.app.FragmentManager; 6 import android.support.v4.app.FragmentPagerAdapter; 7 import android.support.v4.app.FragmentStatePagerAdapter; 8 import android.support.v4.view.ViewPager; 9 import android.support.v7.app.AppCompatActivity; 10 import android.os.Bundle; 11 import android.view.View; 12 import android.widget.HorizontalScrollView; 13 import android.widget.LinearLayout; 14 import android.widget.TextView; 15 import android.widget.Toast; 16 17 import java.util.ArrayList; 18 import java.util.List; 19 20 public class MainActivity extends AppCompatActivity { 21 22 private HorizontalScrollView hsv; 23 private LinearLayout linMenu; 24 private ViewPager viewPager; 25 26 //存放菜单TextView组件 27 private List<TextView> menuLists=new ArrayList<>(); 28 29 private List<String> menuText=new ArrayList<>(); 30 private List<String> tabsType=new ArrayList<>(); 31 32 33 @Override 34 protected void onCreate(Bundle savedInstanceState) { 35 super.onCreate(savedInstanceState); 36 setContentView(R.layout.activity_main); 37 38 hsv = findViewById(R.id.hsv); 39 linMenu = findViewById(R.id.lin_menu); 40 viewPager = findViewById(R.id.vp); 41 42 //初使化数据 43 initData(); 44 45 //初使化横向滑动菜单 46 initMenu(); 47 48 //设置viewpager的适配器 49 MyPagerAdapter adapter=new MyPagerAdapter(getSupportFragmentManager()); 50 viewPager.setAdapter(adapter); 51 52 viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { 53 @Override 54 public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 55 56 } 57 58 @Override 59 public void onPageSelected(int position) { 60 //设置选中的菜单,改变文本颜色 61 setSelectedMenu(position); 62 //设置滚动 63 setScrollMenu(position); 64 65 66 } 67 68 @Override 69 public void onPageScrollStateChanged(int state) { 70 71 } 72 }); 73 74 viewPager.setOffscreenPageLimit(menuText.size()); 75 76 } 77 78 /** 79 * 设置横向滑动菜单 滚动到 指定的菜单 项 80 * @param index 81 */ 82 private void setScrollMenu(int index){ 83 //得到组件 84 TextView tvMenu=menuLists.get(index); 85 float tx = tvMenu.getX();//得到x坐标 86 //scrollTo(x,y):滚动 y-代表垂直方向的滚动 x-代表水平方向的滚动 87 hsv.scrollTo((int)tx,0); 88 } 89 90 private void initData() { 91 menuText.add("头条"); 92 menuText.add("社会"); 93 menuText.add("国内"); 94 menuText.add("国际"); 95 menuText.add("娱乐"); 96 menuText.add("体育"); 97 menuText.add("军事"); 98 menuText.add("科技"); 99 menuText.add("财经"); 100 menuText.add("时尚"); 101 102 tabsType.add("top"); 103 tabsType.add("shehui"); 104 tabsType.add("guonei"); 105 tabsType.add("guoji"); 106 tabsType.add("yule"); 107 tabsType.add("tiyu"); 108 tabsType.add("junshi"); 109 tabsType.add("keji"); 110 tabsType.add("caijing"); 111 tabsType.add("shishang"); 112 } 113 114 private void initMenu() { 115 //将TextView组件 添加到 linMenu 组件中 116 for (int i = 0; i < menuText.size(); i++) { 117 //创建菜单 TextView 118 TextView textView = new TextView(this); 119 textView.setText(menuText.get(i)); 120 121 if (i == 0) { 122 textView.setTextColor(Color.RED);//设置字体颜色是红色 123 } else { 124 textView.setTextColor(Color.BLACK);//设置字体颜色是黑色 125 } 126 //设置标签,用来记录它是第几个菜单 127 textView.setTag(i); 128 129 //添加点击事件 130 textView.setOnClickListener(new View.OnClickListener() { 131 @Override 132 public void onClick(View view) { 133 //viewpager切换到不同的页面 134 viewPager.setCurrentItem(Integer.parseInt(view.getTag() + "")); 135 //设置颜色 136 setSelectedMenu(Integer.parseInt(view.getTag() + "")); 137 } 138 }); 139 140 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 141 params.setMargins(0, 5, 8, 0);//设置菜单之间的间隔 142 143 //进行添加 addView 144 linMenu.addView(textView, params); 145 //添加到集合中 146 menuLists.add(textView); 147 } 148 } 149 150 /** 151 * 将所有的菜单遍历一遍,设置选中的菜单字体颜色为红色,其余是黑色 152 * @param menuIndex 153 */ 154 private void setSelectedMenu(int menuIndex){//menuIndex:当前选中菜单的下标 155 for(int i=0;i<menuLists.size();i++){ 156 if(i==menuIndex){ 157 menuLists.get(i).setTextColor(Color.RED);//选中的颜色 158 }else { 159 menuLists.get(i).setTextColor(Color.BLACK); 160 161 } 162 } 163 } 164 165 166 class MyPagerAdapter extends FragmentPagerAdapter { 167 public MyPagerAdapter(FragmentManager fm) { 168 super(fm); 169 } 170 171 //用来返回每个页面 172 @Override 173 public Fragment getItem(int position) {//position:页面的下标 174 RecommendFr fr=new RecommendFr(); 175 Bundle bundle=new Bundle(); 176 bundle.putString("tt",tabsType.get(position)); 177 fr.setArguments(bundle); 178 Toast.makeText(MainActivity.this,tabsType.get(position)+"--"+position,Toast.LENGTH_SHORT).show(); 179 return fr; 180 } 181 182 //返回页面的数量 183 @Override 184 public int getCount() { 185 return menuText.size(); 186 } 187 } 188 }
activity_main
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 > 8 9 <!--横向菜单 只能有一个子孩子 --> 10 <HorizontalScrollView 11 android:layout_width="match_parent" 12 android:layout_height="wrap_content" 13 android:id="@+id/hsv"> 14 <LinearLayout 15 android:layout_width="match_parent" 16 android:layout_height="40dp" 17 android:orientation="horizontal" 18 android:id="@+id/lin_menu"> 19 20 </LinearLayout> 21 22 </HorizontalScrollView> 23 24 <!--viewPager实现页面的滑动--> 25 <android.support.v4.view.ViewPager 26 android:layout_width="match_parent" 27 android:layout_height="match_parent" 28 android:id="@+id/vp" 29 android:layout_below="@id/hsv"></android.support.v4.view.ViewPager> 30 31 32 33 </RelativeLayout>
MyPagerAdapter
1 package zhanghaijiao.bawei.com.yuekao_moni.adapter; 2 3 import android.content.Context; 4 import android.graphics.Bitmap; 5 import android.view.View; 6 import android.view.ViewGroup; 7 import android.widget.BaseAdapter; 8 import android.widget.ImageView; 9 import android.widget.TextView; 10 11 import com.nostra13.universalimageloader.core.DisplayImageOptions; 12 import com.nostra13.universalimageloader.core.ImageLoader; 13 import com.nostra13.universalimageloader.core.assist.ImageScaleType; 14 15 import java.util.List; 16 17 import zhanghaijiao.bawei.com.yuekao_moni.R; 18 import zhanghaijiao.bawei.com.yuekao_moni.bean.ResultData; 19 20 21 /** 22 * Created by jane on 2018/2/27. 23 */ 24 25 public class MyLvAdapter extends BaseAdapter { 26 27 28 private Context context; 29 private List<ResultData.ResultBean.DataBean> results; 30 31 private final int ONE=0; 32 private final int TWO=1; 33 private final int THREE=2; 34 35 private DisplayImageOptions options; 36 37 public MyLvAdapter(Context context, List<ResultData.ResultBean.DataBean> results) { 38 this.context = context; 39 this.results = results; 40 options = new DisplayImageOptions.Builder() 41 .cacheInMemory(true)//使用内存缓存 42 .cacheOnDisk(true)//使用磁盘缓存 43 .bitmapConfig(Bitmap.Config.RGB_565)//设置图片色彩模式 44 .imageScaleType(ImageScaleType.EXACTLY)//设置图片的缩放模式 45 // .displayer(new RoundedBitmapDisplayer(50))//设置圆角 46 .build(); 47 } 48 49 @Override 50 public int getViewTypeCount() { 51 return 3; 52 } 53 54 @Override 55 public int getItemViewType(int position) { 56 //得到以下三个图片url 57 String s=results.get(position).getThumbnail_pic_s(); 58 String s02=results.get(position).getThumbnail_pic_s02(); 59 String s03=results.get(position).getThumbnail_pic_s03(); 60 61 if(s!=null && s02==null && s03==null){ 62 return ONE; 63 }else if(s==null && s02!=null && s03!=null){ 64 return TWO; 65 }else if(s!=null && s02!=null && s03!=null){ 66 return THREE; 67 }else { 68 return ONE; 69 } 70 71 } 72 73 @Override 74 public int getCount() { 75 return results.size(); 76 } 77 78 @Override 79 public Object getItem(int i) { 80 return null; 81 } 82 83 @Override 84 public long getItemId(int i) { 85 return 0; 86 } 87 88 @Override 89 public View getView(int i, View view, ViewGroup viewGroup) { 90 int type = getItemViewType(i); 91 if(type==ONE){ 92 ViewHolder1 viewHolder1 = null; 93 if (view==null){ 94 view= View.inflate(context, R.layout.one_img,null); 95 viewHolder1 = new ViewHolder1(); 96 viewHolder1.img1 = view.findViewById(R.id.img1); 97 viewHolder1.title1 = view.findViewById(R.id.tv_title); 98 view.setTag(viewHolder1); 99 }else{ 100 viewHolder1= (ViewHolder1) view.getTag(); 101 } 102 viewHolder1.title1.setText(results.get(i).getTitle()); 103 ImageLoader.getInstance().displayImage(results.get(i).getThumbnail_pic_s(), viewHolder1.img1, options); 104 return view; 105 106 }else if(type==TWO){ 107 ViewHolder2 viewHolder2 = null; 108 if (view==null){ 109 view= View.inflate(context,R.layout.two_img,null); 110 viewHolder2 = new ViewHolder2(); 111 viewHolder2.img1 = view.findViewById(R.id.img1); 112 viewHolder2.img2 = view.findViewById(R.id.img2); 113 viewHolder2.title1 = view.findViewById(R.id.tv_title); 114 view.setTag(viewHolder2); 115 }else{ 116 viewHolder2= (ViewHolder2) view.getTag(); 117 } 118 viewHolder2.title1.setText(results.get(i).getTitle()); 119 ImageLoader.getInstance().displayImage(results.get(i).getThumbnail_pic_s(), viewHolder2.img1, options); 120 ImageLoader.getInstance().displayImage(results.get(i).getThumbnail_pic_s02(), viewHolder2.img2, options); 121 return view; 122 }else if(type==THREE){ 123 ViewHolder3 viewHolder3 = null; 124 if (view==null){ 125 view= View.inflate(context,R.layout.three_img,null); 126 viewHolder3 = new ViewHolder3(); 127 viewHolder3.img1 = view.findViewById(R.id.img1); 128 viewHolder3.img2 = view.findViewById(R.id.img2); 129 viewHolder3.img3 = view.findViewById(R.id.img3); 130 viewHolder3.title1 = view.findViewById(R.id.tv_title); 131 view.setTag(viewHolder3); 132 }else{ 133 viewHolder3= (ViewHolder3) view.getTag(); 134 } 135 viewHolder3.title1.setText(results.get(i).getTitle()); 136 ImageLoader.getInstance().displayImage(results.get(i).getThumbnail_pic_s(), viewHolder3.img1, options); 137 ImageLoader.getInstance().displayImage(results.get(i).getThumbnail_pic_s02(), viewHolder3.img2, options); 138 ImageLoader.getInstance().displayImage(results.get(i).getThumbnail_pic_s03(), viewHolder3.img2, options); 139 return view; 140 }else { 141 return null; 142 } 143 } 144 145 146 class ViewHolder1{ 147 TextView title1; 148 ImageView img1; 149 } 150 class ViewHolder2{ 151 TextView title1; 152 ImageView img1; 153 ImageView img2; 154 } 155 class ViewHolder3{ 156 TextView title1; 157 ImageView img1; 158 ImageView img2; 159 ImageView img3; 160 } 161 }
MyApp
1 package zhanghaijiao.bawei.com.yuekao_moni; 2 3 import android.app.Application; 4 import android.os.Environment; 5 6 import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache; 7 import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; 8 import com.nostra13.universalimageloader.core.ImageLoader; 9 import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; 10 11 import java.io.File; 12 13 /** 14 * Created by Administrator on 2018/2/22 0022. 15 */ 16 17 public class MyApp extends Application { 18 @Override 19 public void onCreate() { 20 super.onCreate(); 21 File cachefile = new File(Environment.getExternalStorageDirectory().getPath()+"/idm"); 22 ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this) 23 .memoryCacheExtraOptions(480, 800)//缓存图片最大的长和宽 24 .threadPoolSize(2)//线程池的数量 25 .threadPriority(4) 26 .memoryCacheSize(30*1024*1024)//设置内存缓存区大小 27 .diskCacheSize(30*1024*1024)//设置sd卡缓存区大小 28 .diskCache(new UnlimitedDiscCache(cachefile))//自定义缓存目录 29 .writeDebugLogs()//打印日志内容 30 .diskCacheFileNameGenerator(new Md5FileNameGenerator())//给缓存的文件名进行md5加密处理 31 .build(); 32 ImageLoader.getInstance().init(configuration); 33 } 34 }
RecommendFr
1 package zhanghaijiao.bawei.com.yuekao_moni; 2 3 import android.os.Bundle; 4 import android.os.Handler; 5 import android.os.Message; 6 import android.support.annotation.Nullable; 7 import android.support.v4.app.Fragment; 8 import android.util.Log; 9 import android.view.LayoutInflater; 10 import android.view.View; 11 import android.view.ViewGroup; 12 import android.widget.ListView; 13 import android.widget.Toast; 14 15 import com.google.gson.Gson; 16 import com.google.gson.reflect.TypeToken; 17 18 import java.io.BufferedReader; 19 import java.io.IOException; 20 import java.io.InputStream; 21 import java.io.InputStreamReader; 22 import java.lang.reflect.Type; 23 import java.net.HttpURLConnection; 24 import java.net.URL; 25 import java.util.ArrayList; 26 import java.util.List; 27 28 import zhanghaijiao.bawei.com.yuekao_moni.adapter.MyLvAdapter; 29 import zhanghaijiao.bawei.com.yuekao_moni.bean.ResultData; 30 import zhanghaijiao.bawei.com.yuekao_moni.utils.MyTask; 31 import zhanghaijiao.bawei.com.yuekao_moni.utils.NetStateUtil; 32 33 34 /** 35 * Created by jane on 2018/3/1. 36 */ 37 38 public class RecommendFr extends Fragment { 39 40 private String urlpath=""; 41 private ListView listView; 42 private MyLvAdapter adapter; 43 44 private Handler myHandler=new Handler(){ 45 @Override 46 public void handleMessage(Message msg) { 47 48 49 //设置适配器,进行显示 50 List<ResultData.ResultBean.DataBean> data =(List<ResultData.ResultBean.DataBean>) msg.obj; 51 //设置适配器 52 MyLvAdapter adapter=new MyLvAdapter(getActivity(),data); 53 listView.setAdapter(adapter); 54 55 56 } 57 }; 58 59 @Nullable 60 @Override 61 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 62 View v=inflater.inflate(R.layout.recomend,container,false); 63 listView = v.findViewById(R.id.lv); 64 65 //接收参数并拼接字符串 66 Bundle arguments = getArguments(); 67 String str=arguments.getString("tt"); 68 urlpath="http://v.juhe.cn/toutiao/index?type="+str+"&key=597b4f9dcb50e051fd725a9ec54d6653"; 69 70 return v; 71 } 72 73 @Override 74 public void onActivityCreated(@Nullable Bundle savedInstanceState) { 75 super.onActivityCreated(savedInstanceState); 76 77 //请求数据 78 requestNetData(); 79 } 80 81 private void requestNetData() { 82 83 if(NetStateUtil.isConn(getActivity())){ 84 //进行网络请求 85 new Thread(){ 86 @Override 87 public void run() { 88 getData(); 89 } 90 }.start(); 91 92 }else { 93 NetStateUtil.showNoNetWorkDlg(getActivity()); 94 95 } 96 97 98 99 100 } 101 102 private void getData() { 103 104 try { 105 URL url=new URL(urlpath); 106 HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 107 urlConnection.setRequestMethod("GET"); 108 urlConnection.setConnectTimeout(5000); 109 urlConnection.setReadTimeout(5000); 110 111 int code=urlConnection.getResponseCode(); 112 if(code==200){ 113 //获取数据 114 InputStream inputStream = urlConnection.getInputStream(); 115 String jsonData=inputstreamToString(inputStream); 116 117 //进行解析 118 Gson gson=new Gson(); 119 ResultData rdata=gson.fromJson(jsonData, ResultData.class); 120 121 //给主线程发送消息 122 Message msg=Message.obtain(); 123 msg.obj=rdata.getResult().getData(); 124 myHandler.sendMessage(msg); 125 } 126 127 128 129 130 } catch (Exception e) { 131 e.printStackTrace(); 132 } 133 134 135 } 136 public String inputstreamToString(InputStream stream){ 137 StringBuilder builder=new StringBuilder(); 138 139 try { 140 BufferedReader reader=new BufferedReader(new InputStreamReader(stream)); 141 String str; 142 while ((str=reader.readLine())!=null){ 143 builder.append(str); 144 } 145 } catch (IOException e) { 146 e.printStackTrace(); 147 } 148 149 return builder.toString(); 150 151 } 152 153 154 }
ResultData
....
MyTask
1 package zhanghaijiao.bawei.com.yuekao_moni.utils; 2 3 import android.os.AsyncTask; 4 5 import java.io.BufferedReader; 6 import java.io.InputStream; 7 import java.io.InputStreamReader; 8 import java.net.HttpURLConnection; 9 import java.net.URL; 10 11 /** 12 * Created by jane on 2018/2/28. 13 */ 14 15 public class MyTask extends AsyncTask<String,Void,String> { 16 17 //2.声明接口变量 18 private ICallBacks iCallBacks; 19 20 //3.定义带参构造方法 21 public MyTask(ICallBacks iCallBacks) { 22 this.iCallBacks = iCallBacks; 23 } 24 25 @Override 26 protected String doInBackground(String... strings) { 27 String str=""; 28 try { 29 URL url = new URL(strings[0]); 30 HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 31 urlConnection.setRequestMethod("GET"); 32 urlConnection.setConnectTimeout(5000); 33 urlConnection.setReadTimeout(5000); 34 int responseCode = urlConnection.getResponseCode(); 35 if (responseCode==200){ 36 InputStream inputStream = urlConnection.getInputStream(); 37 str=toJson(inputStream); 38 } 39 } catch (Exception e) { 40 e.printStackTrace(); 41 } 42 return str; 43 } 44 45 @Override 46 protected void onPostExecute(String s) { 47 super.onPostExecute(s); 48 //4.调用接口的方法 49 iCallBacks.getJsonData(s); 50 51 } 52 53 54 //1.定义一个内部接口 55 public interface ICallBacks{ 56 //得到json串 57 void getJsonData(String jsonstr); 58 } 59 60 private String toJson(InputStream inputStream) { 61 StringBuilder builder = new StringBuilder(); 62 String string; 63 InputStreamReader in = new InputStreamReader(inputStream); 64 BufferedReader reader = new BufferedReader(in); 65 try { 66 while ((string=reader.readLine())!=null){ 67 builder.append(string); 68 } 69 } catch (Exception e) { 70 e.printStackTrace(); 71 } 72 return builder.toString(); 73 } 74 }
NetStateUtil
1 package zhanghaijiao.bawei.com.yuekao_moni.utils; 2 3 import android.app.AlertDialog; 4 import android.content.Context; 5 import android.content.DialogInterface; 6 import android.content.Intent; 7 import android.net.ConnectivityManager; 8 import android.net.NetworkInfo; 9 10 import zhanghaijiao.bawei.com.yuekao_moni.R; 11 12 13 /** 14 * 得到网络状态的工具类 15 * Created by e531 on 2017/10/16. 16 */ 17 public class NetStateUtil { 18 19 /* 20 * 判断网络连接是否已开 21 * true 已打开 false 未打开 22 * */ 23 public static boolean isConn(Context context){ 24 boolean bisConnFlag=false; 25 ConnectivityManager conManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); 26 NetworkInfo network = conManager.getActiveNetworkInfo(); 27 if(network!=null){ 28 bisConnFlag=conManager.getActiveNetworkInfo().isAvailable(); 29 } 30 return bisConnFlag; 31 } 32 33 /** 34 * 当判断当前手机没有网络时选择是否打开网络设置 35 * @param context 36 */ 37 public static void showNoNetWorkDlg(final Context context) { 38 AlertDialog.Builder builder = new AlertDialog.Builder(context); 39 builder.setIcon(R.mipmap.ic_launcher) // 40 .setTitle(R.string.app_name) // 41 .setMessage("当前无网络").setPositiveButton("设置", new DialogInterface.OnClickListener() { 42 43 @Override 44 public void onClick(DialogInterface dialog, int which) { 45 // 跳转到系统的网络设置界面 46 Intent intent = null; 47 // 先判断当前系统版本 48 if(android.os.Build.VERSION.SDK_INT > 10){ // 3.0以上 49 intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); 50 }else{ 51 intent = new Intent(); 52 intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings"); 53 } 54 context.startActivity(intent); 55 56 } 57 }).setNegativeButton("知道了", null).show(); 58 } 59 }
one—img
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 <TextView 7 android:layout_width="wrap_content" 8 android:layout_height="wrap_content" 9 android:id="@+id/tv_title"/> 10 <ImageView 11 android:layout_width="80dp" 12 android:layout_height="80dp" 13 android:id="@+id/img1" 14 android:layout_below="@id/tv_title"/> 15 16 </RelativeLayout>
two—img
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 <TextView 7 android:layout_width="wrap_content" 8 android:layout_height="wrap_content" 9 android:id="@+id/tv_title"/> 10 <LinearLayout 11 android:layout_width="match_parent" 12 android:layout_height="wrap_content" 13 android:orientation="horizontal" 14 android:layout_below="@id/tv_title"> 15 <ImageView 16 android:layout_width="80dp" 17 android:layout_height="80dp" 18 android:id="@+id/img1"/> 19 <ImageView 20 android:layout_width="80dp" 21 android:layout_height="80dp" 22 android:id="@+id/img2"/> 23 24 </LinearLayout> 25 26 27 </RelativeLayout>
three——img
1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 6 <TextView 7 android:layout_width="wrap_content" 8 android:layout_height="wrap_content" 9 android:id="@+id/tv_title"/> 10 <LinearLayout 11 android:layout_width="match_parent" 12 android:layout_height="wrap_content" 13 android:orientation="horizontal" 14 android:layout_below="@id/tv_title"> 15 <ImageView 16 android:layout_width="80dp" 17 android:layout_height="80dp" 18 android:id="@+id/img1"/> 19 <ImageView 20 android:layout_width="80dp" 21 android:layout_height="80dp" 22 android:id="@+id/img2"/> 23 <ImageView 24 android:layout_width="80dp" 25 android:layout_height="80dp" 26 android:id="@+id/img3"/> 27 </LinearLayout> 28 29 30 </RelativeLayout>
recumend
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="match_parent"> 5 6 <ListView 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 android:id="@+id/lv"></ListView> 10 11 </RelativeLayout>
权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>