Android中使用ScrollView實現(xiàn)滑動到底部顯示加載更多
這是效果

主要是onTouchListener監(jiān)聽事件,監(jiān)視什么時候滑到底部
同時要理解getMeasuredHeight和getHeight的區(qū)別
getMeasuredHeight:全部的長度 包括隱藏的
getHeight:在布局中展示出來的長度
布局文件:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ScrollView android:id="@+id/scrollview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="none" > <TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </ScrollView> <Button android:id="@+id/next" android:layout_gravity="bottom|center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="invisible" android:text="點擊加載更多" /> </FrameLayout>
MainActivity
package com.example.scrollview;
import android.opengl.Visibility;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.NotificationCompat.Action;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private ScrollView scroll;
private TextView text;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
scroll=(ScrollView) findViewById(R.id.scrollview);
text=(TextView) findViewById(R.id.text);
button=(Button) findViewById(R.id.next);
text.setText(getResources().getString(R.string.lyric));
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
text.append(getResources().getString(R.string.lyric));
button.setVisibility(View.INVISIBLE);
}
});
scroll.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_MOVE:{
break;
}
case MotionEvent.ACTION_DOWN:{
break;
}
case MotionEvent.ACTION_UP:{
//當文本的measureheight 等于scroll滾動的長度+scroll的height
if(scroll.getChildAt(0).getMeasuredHeight()<=scroll.getScrollY()+scroll.getHeight()){
button.setVisibility(View.VISIBLE);
}else{
}
break;
}
}
return false;
}
});
}
}
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
- Android ExpandableListView實現(xiàn)下拉刷新和加載更多效果
- Android實踐之帶加載效果的下拉刷新上拉加載更多
- android使用PullToRefresh框架實現(xiàn)ListView下拉刷新上拉加載更多
- Android RecyclerView添加上拉加載更多效果
- Android中RecycleView與ViewPager沖突的解決方法及原理
- Android RecycleView使用(CheckBox全選、反選、單選)
- android中RecycleView添加下滑到底部的監(jiān)聽示例
- Android 使用RecycleView列表實現(xiàn)加載更多的示例代碼
相關(guān)文章
RecycleView實現(xiàn)item側(cè)滑刪除與拖拽
這篇文章主要為大家詳細介紹了RecycleView實現(xiàn)item側(cè)滑刪除與拖拽,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-11-11
Android應(yīng)用的LinearLayout中嵌套RelativeLayout的布局用法
這篇文章主要介紹了Android應(yīng)用的LinearLayout中嵌套RelativeLayout的布局用法,文后還給出了線性布局中一些組件位置的調(diào)試經(jīng)驗,需要的朋友可以參考下2016-04-04
Android 抽屜效果的導(dǎo)航菜單實現(xiàn)代碼實例
本篇文章主要介紹了Android 抽屜效果的導(dǎo)航菜單實現(xiàn)代碼實例,這種側(cè)滑的抽屜效果的菜單很好,有興趣的可以了解一下。2016-12-12
Android RadarView雷達圖(蜘蛛網(wǎng)圖)的實現(xiàn)代碼
這篇文章主要介紹了Android RadarView雷達圖(蜘蛛網(wǎng)圖)的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03
Android使用Retrofit實現(xiàn)自定義Converter解析接口流程詳解
Retrofit是一個RESTful的HTTP網(wǎng)絡(luò)請求框架的封裝,網(wǎng)絡(luò)請求的工作本質(zhì)上是OkHttp完成,而Retrofit僅負責(zé)網(wǎng)絡(luò)請求接口的封裝2023-03-03
Android中監(jiān)聽Home鍵的4種方法總結(jié)
這篇文章主要介紹了Android中監(jiān)聽Home鍵的4種方法總結(jié),本文講解了onSaveInstanceState方法、onUserLeaveHint方法、ACTION_CLOSE_SYSTEM_DIALOGS、framework PhoneWindowManager.java等4種方法,需要的朋友可以參考下2015-04-04
Android編程開發(fā)之EditText中inputType屬性小結(jié)
這篇文章主要介紹了Android編程開發(fā)之EditText中inputType屬性用法,分析說明了Android中EditText的inputType屬性具體含義與使用技巧,需要的朋友可以參考下2016-01-01

