android:ScrollView滑動到底部顯示載入更多

來源:互聯網
上載者:User

標籤:

這是效果

主要是onTouchListener監聽事件,監視什麼時候滑到底部

同時要理解getMeasuredHeight和getHeight的區別

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;@Overrideprotected 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() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubtext.append(getResources().getString(R.string.lyric));button.setVisibility(View.INVISIBLE);}});scroll.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {// TODO Auto-generated method stubswitch(event.getAction()){case MotionEvent.ACTION_MOVE:{break;}case MotionEvent.ACTION_DOWN:{break;}case MotionEvent.ACTION_UP:{//當文本的measureheight 等於scroll滾動的長度+scroll的heightif(scroll.getChildAt(0).getMeasuredHeight()<=scroll.getScrollY()+scroll.getHeight()){button.setVisibility(View.VISIBLE);}else{}break;}}return false;}});}}

突然感覺自己不小了。父母都在關心自己的婚事了

可是我的她又在哪裡 。




android:ScrollView滑動到底部顯示載入更多

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.