Skip to content

Commit

Permalink
增加回到顶部
Browse files Browse the repository at this point in the history
  • Loading branch information
Jude95 committed Sep 27, 2015
1 parent 5d372f4 commit 834b968
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions dome/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.facebook.fresco:fresco:0.5.1'
compile project(':easyrecyclerview')
compile 'com.github.clans:fab:1.6.0'

}
9 changes: 9 additions & 0 deletions dome/src/main/java/com/jude/dome/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.widget.CompoundButton;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.github.clans.fab.FloatingActionButton;
import com.jude.easyrecyclerview.EasyRecyclerView;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;

Expand All @@ -20,6 +21,7 @@

public class MainActivity extends ActionBarActivity implements RecyclerArrayAdapter.OnLoadMoreListener, SwipeRefreshLayout.OnRefreshListener{
private EasyRecyclerView recyclerView;
private FloatingActionButton top;
private PersonAdapter adapter;
private Handler handler;

Expand All @@ -31,6 +33,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fresco.initialize(this);
setContentView(R.layout.activity_main);
top = (FloatingActionButton) findViewById(R.id.top);
recyclerView = (EasyRecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapterWithProgress(adapter = new PersonAdapter(this));
Expand All @@ -42,6 +45,12 @@ public void onClick(View v) {
adapter.resumeMore();
}
});
top.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recyclerView.getRecyclerView().scrollToPosition(0);
}
});
recyclerView.setRefreshListener(this);
handler = new Handler();
addPerson();
Expand Down
Binary file added dome/src/main/res/drawable-xxhdpi/ic_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions dome/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
Expand All @@ -13,4 +13,16 @@
app:layout_empty="@layout/view_empty"
app:layout_progress="@layout/view_progress"
/>
</RelativeLayout>

<com.github.clans.fab.FloatingActionButton
android:id="@+id/top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="16dp"
android:src="@drawable/ic_top"
app:fab_colorNormal="?colorAccent"
app:fab_colorPressed="?colorAccent"
app:fab_size="normal" />

</FrameLayout>
1 change: 1 addition & 0 deletions dome/src/main/res/layout/item_person.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
</LinearLayout>



<View
android:layout_width="match_parent"
android:layout_height="0.3dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_light" />
android:layout_height="match_parent" />


</android.support.v4.widget.SwipeRefreshLayout>
Expand All @@ -22,15 +21,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="@android:color/holo_green_light"
/>

<FrameLayout
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="@android:color/holo_blue_light"
/>

</FrameLayout>

0 comments on commit 834b968

Please sign in to comment.