Android中使用ScrollView實(shí)現(xiàn)滑動(dòng)到底部顯示加載更多
這是效果
主要是onTouchListener監(jiān)聽(tīng)事件,監(jiān)視什么時(shí)候滑到底部
同時(shí)要理解getMeasuredHeight和getHeight的區(qū)別
getMeasuredHeight:全部的長(zhǎng)度 包括隱藏的
getHeight:在布局中展示出來(lái)的長(zhǎng)度
布局文件:
<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="點(diǎn)擊加載更多" /> </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:{ //當(dāng)文本的measureheight 等于scroll滾動(dòng)的長(zhǎng)度+scroll的height if(scroll.getChildAt(0).getMeasuredHeight()<=scroll.getScrollY()+scroll.getHeight()){ button.setVisibility(View.VISIBLE); }else{ } break; } } return false; } }); } }
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!
- Android ExpandableListView實(shí)現(xiàn)下拉刷新和加載更多效果
- Android實(shí)踐之帶加載效果的下拉刷新上拉加載更多
- android使用PullToRefresh框架實(shí)現(xiàn)ListView下拉刷新上拉加載更多
- Android RecyclerView添加上拉加載更多效果
- Android中RecycleView與ViewPager沖突的解決方法及原理
- Android RecycleView使用(CheckBox全選、反選、單選)
- android中RecycleView添加下滑到底部的監(jiān)聽(tīng)示例
- Android 使用RecycleView列表實(shí)現(xiàn)加載更多的示例代碼
相關(guān)文章
RecycleView實(shí)現(xiàn)item側(cè)滑刪除與拖拽
這篇文章主要為大家詳細(xì)介紹了RecycleView實(shí)現(xiàn)item側(cè)滑刪除與拖拽,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11Android應(yīng)用的LinearLayout中嵌套R(shí)elativeLayout的布局用法
這篇文章主要介紹了Android應(yīng)用的LinearLayout中嵌套R(shí)elativeLayout的布局用法,文后還給出了線性布局中一些組件位置的調(diào)試經(jīng)驗(yàn),需要的朋友可以參考下2016-04-04Android 抽屜效果的導(dǎo)航菜單實(shí)現(xiàn)代碼實(shí)例
本篇文章主要介紹了Android 抽屜效果的導(dǎo)航菜單實(shí)現(xiàn)代碼實(shí)例,這種側(cè)滑的抽屜效果的菜單很好,有興趣的可以了解一下。2016-12-12Android RadarView雷達(dá)圖(蜘蛛網(wǎng)圖)的實(shí)現(xiàn)代碼
這篇文章主要介紹了Android RadarView雷達(dá)圖(蜘蛛網(wǎng)圖)的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03Android使用Retrofit實(shí)現(xiàn)自定義Converter解析接口流程詳解
Retrofit是一個(gè)RESTful的HTTP網(wǎng)絡(luò)請(qǐng)求框架的封裝,網(wǎng)絡(luò)請(qǐng)求的工作本質(zhì)上是OkHttp完成,而Retrofit僅負(fù)責(zé)網(wǎng)絡(luò)請(qǐng)求接口的封裝2023-03-03Android中監(jiān)聽(tīng)Home鍵的4種方法總結(jié)
這篇文章主要介紹了Android中監(jiān)聽(tīng)Home鍵的4種方法總結(jié),本文講解了onSaveInstanceState方法、onUserLeaveHint方法、ACTION_CLOSE_SYSTEM_DIALOGS、framework PhoneWindowManager.java等4種方法,需要的朋友可以參考下2015-04-04Android編程開(kāi)發(fā)之EditText中inputType屬性小結(jié)
這篇文章主要介紹了Android編程開(kāi)發(fā)之EditText中inputType屬性用法,分析說(shuō)明了Android中EditText的inputType屬性具體含義與使用技巧,需要的朋友可以參考下2016-01-01Android仿QQ空間主頁(yè)面的實(shí)現(xiàn)
今天模仿安卓QQ空間,打開(kāi)程序的啟動(dòng)畫(huà)面和導(dǎo)航頁(yè)面我就不做了,大家可以模仿微信的那個(gè)做一下,很簡(jiǎn)單。這次主要做一下主頁(yè)面的實(shí)現(xiàn),感興趣的朋友可以參考下2013-01-01