編輯:關於Android編程
在App開發中,對於信息的獲取與演示,不可能全部將其獲取與演示,為了在用戶使用中,給予用戶以友好、方便的用戶體驗,以滑動、下拉的效果動態加載數據的要求就會出現。為此,該效果功能就需要應用到所需要的展示頁面中。
"PullToRefresh"
>
"pullDownFromTop"
value=
"0x1"
>
"pullUpFromBottom"
value=
"0x2"
>
"both"
value=
"0x3"
>
srings.xml
"app_name"
>SampleDemo
"action_settings"
>Settings
"pull_to_refresh_pull_down_label"
>滑動刷新
"pull_to_refresh_release_label"
>釋放刷新
"pull_to_refresh_refreshing_label"
>加載中
"pull_to_refresh_tap_label"
>點擊刷新
第三步:將所需要的圖片文件放入相應的文件夾下面,所用的圖片文件有: import
java.util.LinkedList;
import
com.example.sampledemo.view.PullToRefreshListView;
import
android.os.AsyncTask;
import
android.widget.BaseAdapter;
public
class
PullTask
extends
AsyncTask<
void
,
string=
""
>{
private
PullToRefreshListView
pullToRefreshListView;
//實現下拉刷新與上拉加載的ListView
private
int
pullState;
//記錄判斷,上拉與下拉動作
private
BaseAdapter
baseAdapter;
//ListView適配器,用於提醒ListView數據已經更新
private
LinkedList
linkedList;
public
PullTask(PullToRefreshListView
pullToRefreshListView,
int
pullState,
BaseAdapter
baseAdapter, LinkedList linkedList) {
this
.pullToRefreshListView
= pullToRefreshListView;
this
.pullState
= pullState;
this
.baseAdapter
= baseAdapter;
this
.linkedList
= linkedList;
}
@Override
protected
String
doInBackground(Void... params) {
try
{
Thread.sleep(
1000
);
}
catch
(InterruptedException
e) {
}
return
StringTest;
}
@Override
protected
void
onPostExecute(String
result) {
if
(pullState
==
1
)
{
//name=pullDownFromTop
value=0x1 下拉
linkedList.addFirst(頂部數據);
}
if
(pullState
==
2
)
{
//name=pullUpFromBottom
value=0x2 上拉
linkedList.addLast(底部數據);
}
baseAdapter.notifyDataSetChanged();
pullToRefreshListView.onRefreshComplete();
super
.onPostExecute(result);
}
}
void
,>
import
java.util.LinkedList;
import
com.example.sampledemo.R;
import
android.content.Context;
import
android.view.LayoutInflater;
import
android.view.View;
import
android.view.ViewGroup;
import
android.widget.BaseAdapter;
import
android.widget.TextView;
public
class
PullAdapter
extends
BaseAdapter
{
private
LinkedList
linkedList;
private
LayoutInflater
mInflater;
public
PullAdapter(LinkedList
linkedList, Context context) {
mInflater
= LayoutInflater.from(context);
this
.linkedList
= linkedList;
}
@Override
public
int
getCount()
{
return
linkedList.size();
}
@Override
public
Object
getItem(
int
position)
{
return
linkedList.get(position);
}
@Override
public
long
getItemId(
int
position)
{
return
position;
}
@Override
public
View
getView(
int
position,
View convertView, ViewGroup parent) {
ViewHolder
holder=
null
;
if
(convertView
==
null
)
{
holder
=
new
ViewHolder();
convertView
= mInflater.inflate(R.layout.layout_main_listitem,
null
);
holder.textView
= (TextView) convertView.findViewById(R.id.textView);
convertView.setTag(holder);
}
else
{
holder
= (ViewHolder) convertView.getTag();
}
if
(linkedList.size()>
0
){
final
String
dataStr = linkedList.get(position);
holder.textView.setText(dataStr);
}
return
convertView;
}
private
static
class
ViewHolder {
TextView
textView;
//數據顯示區域
}
}
"#FFFFFF"
android:layout_height=
"match_parent"
android:layout_width=
"match_parent"
android:orientation=
"vertical"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
"left"
android:id=
"@+id/textView"
android:layout_height=
"wrap_content"
android:layout_margintop=
"4dp"
android:layout_width=
"match_parent"
android:textcolor=
"#99CC66"
android:textsize=
"18dp"
>
"fill_parent"
android:layout_width=
"fill_parent"
android:paddingbottom=
"10dip"
android:paddingtop=
"10dp"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
"@+id/pull_to_refresh_text"
android:layout_centerinparent=
"true"
android:layout_height=
"wrap_content"
android:layout_width=
"wrap_content"
android:text=
"@string/pull_to_refresh_pull_down_label"
android:textappearance=
"?android:attr/textAppearanceMedium"
android:textstyle=
"bold"
>
"@+id/pull_to_refresh_progress"
android:indeterminate=
"true"
android:layout_centervertical=
"true"
android:layout_height=
"wrap_content"
android:layout_marginleft=
"30dip"
android:layout_marginright=
"20dip"
android:layout_width=
"wrap_content"
android:visibility=
"gone"
style=
"?android:attr/progressBarStyleSmall"
>
"@+id/pull_to_refresh_image"
android:layout_centervertical=
"true"
android:layout_height=
"wrap_content"
android:layout_marginleft=
"30dip"
android:layout_marginright=
"20dip"
android:layout_width=
"wrap_content"
>
"#FFFFFF"
android:layout_height=
"match_parent"
android:layout_width=
"match_parent"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:cp=
"http://schemas.android.com/apk/res/com.example.sampledemo"
xmlns:tools=
"http://schemas.android.com/tools"
>
"#FFFFFF"
android:cachecolorhint=
"#00000000"
android:divider=
"@android:color/black"
android:dividerheight=
"0.1dip"
android:id=
"@+id/pullrefresh"
android:layout_height=
"fill_parent"
android:layout_width=
"fill_parent"
cp:mode=
"both"
>
import
java.util.Arrays;
import
java.util.LinkedList;
import
com.example.sampledemo.view.PullToRefreshBase.OnRefreshListener;
import
com.example.sampledemo.view.PullToRefreshListView;
import
com.example.sampledemo.view.adapter.PullAdapter;
import
com.example.sampledemo.view.task.PullTask;
import
android.os.Bundle;
import
android.widget.ArrayAdapter;
import
android.widget.ListView;
import
android.app.Activity;
/**
*
@ClassName MainActivity.java
*
@Author MaHaochen
*
@Date 2014-4-30 15:56:47
*/
public
class
MainActivity
extends
Activity
{
private
LinkedList
mListItems;
private
PullToRefreshListView
mPullRefreshListView;
private
ArrayAdapter
mAdapter;
private
ListView
mListView;
private
PullAdapter
pullAdapter;
private
String[]
mStrings = { 初始數據
01
,初始數據
02
,初始數據
03
,初始數據
04
,初始數據
05
};
@Override
protected
void
onCreate(Bundle
savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
}
private
void
initViews()
{
mPullRefreshListView
= (PullToRefreshListView) findViewById(R.id.pullrefresh);
mPullRefreshListView.setOnRefreshListener(mOnrefreshListener);
mListView
= mPullRefreshListView.getRefreshableView();
mListItems
=
new
LinkedList();
mListItems.addAll(Arrays.asList(mStrings));
pullAdapter
=
new
PullAdapter(mListItems,
MainActivity.
this
);
mListView.setAdapter(pullAdapter);
}
OnRefreshListener
mOnrefreshListener =
new
OnRefreshListener()
{
public
void
onRefresh()
{
PullTask
pullTask =
new
PullTask(mPullRefreshListView,
mPullRefreshListView.getRefreshType(),
pullAdapter, mListItems);
pullTask.execute();
}
};
}
本文實例講述了Android編程使用自定義View實現水波進度效果。分享給大家供大家參考,具體如下:首先上效果圖:簡介:1.自動適應屏幕大小;2.水波自動橫向滾動;3.各
之前的代碼是分開寫的,並沒有實現一個完成電話相關服務,這次就給大家來一記猛藥,望大家提出寶貴意見和建議與我分享,感謝! 電話監聽主Activity
麥芒5的正面仍堅持了大黑邊的設計風格,真的很華為,那麼新款的華為麥芒5標配版和高配版有什麼區別呢?高配版如何?讓我們一起來看看吧!華為麥芒5標配版和高配版區
先給大家展示下效果圖,喜歡的朋友可以下載源碼哦。完成這個效果的是使用了 IOS_Dialog_Library下載地址:http://xiazai.jb51.net/201