gpt4 book ai didi

android - 我可以在不使用 ScrollView/ListView 的情况下使用 Pull to Refresh 吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:03:56 31 4
gpt4 key购买 nike

我尝试在我的应用中实现下拉刷新。

我用 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>

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);
}
}

最佳答案

尝试更改 SwipeRefreshLayout 配色方案。

    swipeRefreshLayout.setColorSchemeColors(
Color.RED, Color.GREEN, Color.BLUE, Color.CYAN);

此外,SwipeRefreshLayout 仅在 onRefresh() 完成执行之前可见。

关于android - 我可以在不使用 ScrollView/ListView 的情况下使用 Pull to Refresh 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32156711/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com