1、 Buffer background color

<ListView
android:id="@+id/lv_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:layout_marginTop="60dp"
android:cacheColorHint="#fff"
/>

2、 to ListView Add head layout

a、 Header layout file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <FrameLayout
android:layout_width="match_parent"
android:layout_height="180dp" > <com.itheima.zhsh66.view.HorizontalScrollViewPager
android:id="@+id/vp_tab_detail"
android:layout_width="match_parent"
android:layout_height="match_parent" /> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#a000"
android:padding="5dp" > <TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" title "
android:textColor="#fff"
android:textSize="18sp" /> <com.viewpagerindicator.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="10dip"
app:fillColor="#f00"
app:pageColor="#9e9e9e"
app:radius="3dp"
app:strokeWidth="0dp" />
</RelativeLayout>
</FrameLayout> </LinearLayout>

b、 Add head layout

View view = View.inflate(mActivity, R.layout.pager_tab_detail, null);
ViewUtils.inject(this, view);

View header = View.inflate(mActivity, R.layout.list_header_topnews,
null);
ViewUtils.inject(this, header);// Head layout must also be injected into ViewUtils

// to listview Add head layout
lvList.addHeaderView(header);

import java.util.ArrayList;

import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;
import android.widget.Toast; import com.google.gson.Gson;
import com.itheima.zhsh66.R;
import com.itheima.zhsh66.base.BaseMenuDetailPager;
import com.itheima.zhsh66.domain.NewsData;
import com.itheima.zhsh66.domain.NewsData.News;
import com.itheima.zhsh66.domain.NewsData.TopNews;
import com.itheima.zhsh66.domain.NewsMenuData.NewsTabData;
import com.itheima.zhsh66.global.Constants;
import com.itheima.zhsh66.utils.CacheUtils;
import com.itheima.zhsh66.view.HorizontalScrollViewPager;
import com.itheima.zhsh66.view.RefreshListView;
import com.itheima.zhsh66.view.RefreshListView.OnRefreshListener;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.viewpagerindicator.CirclePageIndicator; /**
* 12 Page object of a tab
*
*/
public class TabDetailPager extends BaseMenuDetailPager { // Web information classified by tab
private NewsTabData mTabData;
// News list data returned from the network
private NewsData mNewsTabData;
// Load the news list url
private String mUrl; // Internet data for headlines
private ArrayList<TopNews> mTopNewsList;
// Data adapter for headlines
private TopNewsAdapter mTopNewsAdapter;
// A collection of news lists
private ArrayList<News> mNewsList;
private NewsAdapter mNewsAdapter; @ViewInject(R.id.vp_tab_detail)
private HorizontalScrollViewPager mViewPager; @ViewInject(R.id.lv_tab_detail)
private RefreshListView lvList; @ViewInject(R.id.indicator)
private CirclePageIndicator mIndicator; @ViewInject(R.id.tv_title)
private TextView tvTopNewsTitle; public TabDetailPager(Activity activity, NewsTabData tabData) {
super(activity);
mTabData = tabData;
mUrl = Constants.SERVER_URL + mTabData.url;
} @Override
public View initView() {
View view = View.inflate(mActivity, R.layout.pager_tab_detail, null);
ViewUtils.inject(this, view); View header = View.inflate(mActivity, R.layout.list_header_topnews,
null);
ViewUtils.inject(this, header);// Head layout must also be injected into ViewUtils // to listview Add head layout
lvList.addHeaderView(header); // Set dropdown refresh monitor
lvList.setOnRefreshListener(new OnRefreshListener() { @Override
public void onRefresh() {
// Loading data from the network
getDataFromServer();
}
}); return view;
} @Override
public void initData() {
String cache = CacheUtils.getCache(mUrl, mActivity);
if (!TextUtils.isEmpty(cache)) {
processResult(cache);
} getDataFromServer();
} private void getDataFromServer() {
HttpUtils utils = new HttpUtils();
utils.send(HttpMethod.GET, mUrl, new RequestCallBack<String>() { @Override
public void onSuccess(ResponseInfo<String> responseInfo) {
String result = responseInfo.result;
processResult(result); System.out.println(" Successful access to the network !!!");
CacheUtils.setCache(mUrl, result, mActivity); // Collapse the drop-down refresh control
lvList.onRefreshComplete(true);
} @Override
public void onFailure(HttpException error, String msg) {
// Collapse the drop-down refresh control
lvList.onRefreshComplete(false); error.printStackTrace();
Toast.makeText(mActivity, msg, Toast.LENGTH_SHORT).show();
}
});
} protected void processResult(String result) {
Gson gson = new Gson();
mNewsTabData = gson.fromJson(result, NewsData.class); // Initialize the headlines
mTopNewsList = mNewsTabData.data.topnews;
if (mTopNewsList != null) {
mTopNewsAdapter = new TopNewsAdapter();
mViewPager.setAdapter(mTopNewsAdapter);
mIndicator.setViewPager(mViewPager);// Connect the indicator with viewpager binding
mIndicator.setSnap(true);// The snapshot model
mIndicator.setOnPageChangeListener(new OnPageChangeListener() { @Override
public void onPageSelected(int position) {
System.out.println("position:" + position);
TopNews topNews = mTopNewsList.get(position);
tvTopNewsTitle.setText(topNews.title);
} @Override
public void onPageScrolled(int position, float positionOffset,
int positionOffsetPixels) {
} @Override
public void onPageScrollStateChanged(int state) {
}
}); mIndicator.onPageSelected(0);// Zero the dot , It will still record the last position when the page is destroyed bug
tvTopNewsTitle.setText(mTopNewsList.get(0).title);// Initialize the first page title
} // Initialize the news list
mNewsList = mNewsTabData.data.news;
if (mNewsList != null) {
mNewsAdapter = new NewsAdapter();
lvList.setAdapter(mNewsAdapter);
}
} class TopNewsAdapter extends PagerAdapter { BitmapUtils mBitmapUtils; public TopNewsAdapter() {
// initialization xutils Tools for loading images in
mBitmapUtils = new BitmapUtils(mActivity);
// Set the default load picture
mBitmapUtils
.configDefaultLoadingImage(R.drawable.topnews_item_default);
} @Override
public int getCount() {
return mTopNewsList.size();
} @Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
} @Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView view = new ImageView(mActivity);
view.setScaleType(ScaleType.FIT_XY);// Set the picture fill effect , Represents filling the parent form
// Get links to pictures , Use the link to download the image , Set the picture to ImageView, Consider memory overflow , Image local cache
mBitmapUtils.display(view, mTopNewsList.get(position).topimage);
container.addView(view);
return view;
} @Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
} } class NewsAdapter extends BaseAdapter { public BitmapUtils mBitmapUtils; public NewsAdapter() {
mBitmapUtils = new BitmapUtils(mActivity);
mBitmapUtils
.configDefaultLoadingImage(R.drawable.pic_item_list_default);
} @Override
public int getCount() {
return mNewsList.size();
} @Override
public News getItem(int position) {
return mNewsList.get(position);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = View.inflate(mActivity, R.layout.list_item_news,
null);
holder = new ViewHolder();
holder.tvTitle = (TextView) convertView
.findViewById(R.id.tv_title);
holder.tvDate = (TextView) convertView
.findViewById(R.id.tv_date);
holder.ivIcon = (ImageView) convertView
.findViewById(R.id.iv_icon);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
} News news = getItem(position);
holder.tvTitle.setText(news.title);
holder.tvDate.setText(news.pubdate); mBitmapUtils.display(holder.ivIcon, news.listimage); return convertView;
} } static class ViewHolder {
public TextView tvTitle;
public TextView tvDate;
public ImageView ivIcon;
} }

android Project learning essay 9 (ListView Add head layout ) More articles about

  1. android Project learning essay 12 (ListView Add foot layout )

    1.ListView Add foot layout Head layout initHeaderView, stay onTouchEvent Event to display and hide the layout of the head switch Foot layout initFooterView, Implementation interface OnScrollListener, ...

  2. android Project learning essay 13 (ListView Realization ITEM Click event , Persistent read state to local )

    1. Because to LISTVIEW Added two head layouts , So in the click event ITEM The index will increase 2, For example, the original index of the first data should be 0, After adding two head layouts , Its index becomes        2, In order to make LISTVIEW Of ITEM At point ...

  3. android Project learning essay 11 (ListView Drop down refresh prompt )

    1. Set up mHeaderView.setPadding TOPPADING negative , Hide refresh header layout stay onTouchEvent Event for the head layout display hidden switch import java.text.Simp ...

  4. android Project learning essay 16 ( Ad carousels )

    Ad carousels if (mHandler == null) {// Initialize here mHandler , Ensure that messages are not sent repeatedly mHandler = new Handler() { public void ha ...

  5. android Project learning essay 17 (ListView、GridView Show group pictures )

    ListView.GridView Show group pictures , The processing mechanism is the same <?xml version="1.0" encoding="utf-8"?> <Li ...

  6. android Project learning essay 19 (MD5)

    import java.security.MessageDigest; public class MD5Encoder { public static String encode(String str ...

  7. android Project learning essay 18 ( Three level cache )

    xUtils Of BitmapUtils The module uses level 3 cache , Try to use it in the project BitmapUtils Three level cache ( Mechanism ) import com.itheima.zhsh66.R; import andr ...

  8. android Project learning essay 21 (IM、 speech recognition 、 robot 、 Statistics 、 Scan QR code 、 Bar code )

    speech recognition : IFLYTEK voice cloud  http://www.xfyun.cn/ Voice robot simulation public class TalkBean { public String text; public boolean ...

  9. android Project learning essay 20 ( Screen adaptation )

    1. Picture adaptation Put a resource file with the same name , The machine looks for similar resources according to different resolutions 240*320 ldpi 320*480 mdpi 480*800 hdpi 720*1280 xhdpi 2. Layout adaptation In different ...

Random recommendation

  1. PMP Test preparation _ Chapter six _ Project time management

    Project time management Preface Project time management is the most difficult part of project management , Similar to personal time management , If the efficiency of the group is not properly managed , It's below personal efficiency , In order to manage time , From the estimate , Strict analysis and processing are needed from execution to feedback . If the plan is impossible ...

  2. iframe stay ipad safari Display of

    today Heaven is in web Nested a URL or local HTML, Yes iframe, Set up... On your computer scrolling=‘auto’, Width height , A scroll bar will appear . And in the ipad The width and height of the whole page will be displayed on the page .scrollin ...

  3. Learning notes 7-Android SMS transmitter

    Create a new one Android project sns. stay String.xml Add text <resources> <stringname="app_name">Sns Send a text message &l ...

  4. SQL Get a list of dates in a time period

    declare @start date,@end date; set @start='2010-01-01'; set @end='2010-02-01'; -- Get a list of dates in a time period select [ ...

  5. Yeluzi manong series (3)plotly Simple routines for visualization

    Once again, I want to report to the client , Are the pictures ready ?matplotlib It's ugly to draw a picture ? That will work plotly Well , Make your picture look like it's exploding ~ P1  cause First contact plotly This library is in a project of train signal data mining , ...

  6. Python( 3、 ... and ) And Python Overview of expressions and statements for

    Python Common expression operators : Arithmetic operator : x+y, x-y, x / y, x*y, x // y, x%y Comparison operator : x>y, x<y, x>=y, x<=y, x ...

  7. jmap hit dump abnormal

    background use jmap hit dump The file often encounters the following exception , Can't fight it out , I'm going to tell you the ultimate solution today , SHH , Don't sue others .. Attaching to core -F from executable 421442, ...

  8. CentOS File search find

    1. File search , The built-in command is find usage : find [ Find the path ] Look for conditions operation The default path is the current directory : The default expression is -print 2. main parameter : -name Match name -perm Match permissions (mod ...

  9. OM Responsibility Flow

  10. Murano Weekly Meeting 2016.06.21

    Meeting time: 2016.June.21 1:00~2:00 Chairperson:  Kirill Zaitsev, from Mirantis Meeting summary: 1. ...