Jso*_*son 8 android listview pull-to-refresh android-studio
我试图在我的应用程序中实现Pull to Refresh.
我用android.support.v4.widget.SwipeRefreshLayout包装我的xml代码并且它正常工作,但GUI看起来不太好.
当我向下拉时,我应该看到带有我定义的颜色的常规动画圆圈图标,对吧?但是我认为它是一个空白圆圈,而不是一个带有颜色的转动.
此外,我不能"玩"它甚至在我拉动它之后保持一段时间,它会下降一秒钟(做它做的事情)然后消失.
我认为这是因为我没有使用ListView而是使用LinearLayout.
你怎么看?
XML:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/swipe">
<LinearLayout
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#7B68EE"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".HomeActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/loin"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/welcome"
android:textColor="#B0C4DE"
android:id="@+id/welcomeBackID"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/webViewCurren"
android:layout_alignEnd="@+id/webViewCurren" />
....
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
Java的:
public class HomeActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
SwipeRefreshLayout mSwipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe);
mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_green_light,
android.R.color.holo_blue_bright,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
mSwipeRefreshLayout.setOnRefreshListener(this);
@Override
public void onRefresh() {
Toast.makeText(this, "Refresh", Toast.LENGTH_SHORT).show();
sharedPrefEditor.putString("coordinateX", "34.7");
sharedPrefEditor.putString("coordinateY", "32.5");
sharedPrefEditor.putString("saved", "false");
sharedPrefEditor.commit();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(false);
}
}, 3000);
}
}
Run Code Online (Sandbox Code Playgroud)
尝试更改SwipeRefreshLayout配色方案。
swipeRefreshLayout.setColorSchemeColors(
Color.RED, Color.GREEN, Color.BLUE, Color.CYAN);
Run Code Online (Sandbox Code Playgroud)
此外,只有在完成执行SwipeRefreshLayout后才可见。onRefresh()
| 归档时间: |
|
| 查看次数: |
1758 次 |
| 最近记录: |