【发布时间】:2014-04-11 14:02:32
【问题描述】:
背景
Google 最近发布了an update to its support library,现在有一个新的“SwipeRefreshLayout”视图。
视图允许包裹另一个视图,同时支持向下滑动以执行刷新操作。
截图:
问题
Google 没有提供样本(至少我还没有找到),所以我自己尝试使用它。
一开始我每次刷卡都会崩溃 (NPE),但后来我发现那是因为我没有为它提供“OnRefreshListener”。
但是我还是不知道怎么用,更别说自定义了
这是布局文件的 XML:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.swiperefreshlayouttest.MainActivity"
tools:ignore="MergeRootFrame" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TTT"
android:textSize="40sp" />
</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
代码,虽然它根本没有做任何特别的事情:
public class MainActivity extends ActionBarActivity
{
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SwipeRefreshLayout swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.container);
swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener()
{
@Override
public void onRefresh()
{
// do nothing
}
});
}
}
问题
使用此视图的正确方法是什么?
如何自定义它?目前它只是一条黑线......
【问题讨论】:
-
没有意识到这是在官方的android sdk中。显然这家伙已经想通了,antonioleiva.com/swiperefreshlayout
-
你能展示一下你是如何在java代码中实现它的吗?
-
@Rperryng 我没有。我所做的只是添加一个什么都不做的监听器。代码本身位于支持库中。所以你说这些是唯一可用的功能?
-
@ZohraKhan 这不是支持库类。
标签: android android-support-library swiperefreshlayout