导入依赖
compile 'com.facebook.fresco:fresco:1.5.0'
MyApp.java
public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); Fresco.initialize(this); } }
清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="bw.com.test_demo"> <uses-permission android:name="android.permission.INTERNET"/> <application android:name=".MyApp" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter>
页面
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <ScrollView 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:id="@+id/scroll_view_id"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="150dp" android:text="我是第一个TextView" android:textSize="30sp" android:gravity="center" android:background="@color/colorAccent" /> <ListView android:layout_width="match_parent" android:layout_height="500dp" android:id="@+id/lv_id" /> <TextView android:layout_width="match_parent" android:layout_height="120dp" android:text="我是第二个TextView" android:textSize="30sp" android:gravity="center" android:background="@color/colorPrimary" /> </LinearLayout> </ScrollView>
custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fersco="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/sdv_id" android:layout_width="200dp" android:layout_height="200dp" fersco:placeholderImage="@mipmap/ic_launcher" fersco:roundAsCircle="true" /> </LinearLayout>
MainActivity.java
package bw.com.test_demo; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.view.MotionEvent; import android.view.View; import android.widget.AbsListView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.ScrollView; import android.widget.Toast; import com.facebook.drawee.view.SimpleDraweeView; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { private ListView mLv; private List<String> data; private ArrayAdapter adapter; private ScrollView mSv; private boolean islast;//是否到达底部 private boolean isfirst; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mLv = (ListView) findViewById(R.id.lv_id); mSv = (ScrollView) findViewById(R.id.scroll_view_id); //构建数据源 data = new ArrayList<>(); for(int i = 0;i<100;i++) { data.add("Item ---- > " + i); } //初始化适配器 adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,data); mLv.setAdapter(adapter); //TODO 为ListView 设置触摸事件监听器 mLv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { //如果listVIew 触摸事件监听器中, 事件如果抬起的状态 --则让ScrollView 来处理事件 if(event.getAction() == MotionEvent.ACTION_UP) { //ScrollView 来消费事件 //注册 不接收 事件拦截 mSv.requestDisallowInterceptTouchEvent(false);//消费 }else { //否则, 让ListView 来处理 mSv.requestDisallowInterceptTouchEvent(true);//不消费 } return false; } }); mLv.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if(islast && scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { //ListView移动到底部 AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); View customView = getLayoutInflater().inflate(R.layout.custom_dialog,null); SimpleDraweeView sdv = (SimpleDraweeView) customView.findViewById(R.id.sdv_id); sdv.setImageURI(Uri.parse("http://cs.vmoiver.com/Uploads/cover/2016-11-22/58341f270a239_cut.jpeg")); builder.setView(customView); builder.show(); } if (isfirst && scrollState ==AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) { //TODO --- 获取aidl 的数据----http://blog.csdn.net/xiuxiu_861223/article/details/79347459 Toast.makeText(MainActivity.this, "获取aidl 显示的数据", Toast.LENGTH_SHORT).show(); } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { islast = (firstVisibleItem+visibleItemCount == totalItemCount); if(firstVisibleItem ==0) { isfirst = true; } } }); } }