0

由于某种原因,列表视图没有动画,只有文本视图。我感觉它与 LayoutInflater 有关,但我不确定。这是我定义 JazzyListView 及其动画的地方:

public class RssFragment extends Fragment implements AdapterView.OnItemClickListener {

private ProgressBar progressBar;
private View view;
private View view2;
private JazzyListView listView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (view == null) {

        view = inflater.inflate(R.layout.fragment_layout,container, false);
        progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
 listView= (JazzyListView) view.findViewById(R.id.listView);
        listView.setOnItemClickListener(this);
        startService();
    } else {
        
    }
    return view;
}

private void startService() {
    Intent intent = new Intent(getActivity(), RssService.class);
    intent.putExtra(RssService.RECEIVER, resultReceiver);
    getActivity().startService(intent);
}


private final ResultReceiver resultReceiver = new ResultReceiver(new Handler()) {
    @SuppressWarnings("unchecked")
    @Override
    protected void onReceiveResult(int resultCode, Bundle resultData) {
        List<RssItem> items = (List<RssItem>) resultData.getSerializable(RssService.ITEMS);

        if (items != null) {
            RssAdapter adapter = new RssAdapter(getActivity(), items);
            listView.setAdapter(adapter);


        } else {
            Toast.makeText(getActivity(), "The RSS feed is unable to be downloaded at this time",
                    Toast.LENGTH_LONG).show();
        }

        progressBar.setVisibility(View.GONE);
        listView.setTransitionEffect(JazzyHelper.GROW);
        listView.setVisibility(View.VISIBLE);
    };
};

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    RssAdapter adapter = (RssAdapter) parent.getAdapter();
    RssItem item = (RssItem) adapter.getItem(position);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    startActivity(intent);
}
}

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:baselineAligned="false">

 <ImageView
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:id="@+id/imageView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="#ff090eae"  />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="KGHS"
    android:id="@+id/button"
    android:layout_alignBottom="@+id/imageView"
    android:layout_centerHorizontal="true" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton"
    android:layout_alignBottom="@+id/imageView"
    android:layout_alignParentRight="true"
    />

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" />

<com.twotoasters.jazzylistview.JazzyListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/listView"
    android:divider="#b5b5b5"
    app:effect= "grow"
    android:dividerHeight="10dp"
    android:layout_below="@+id/searchView"
    android:layout_marginBottom="60dp"/>

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView2"
    android:layout_below="@id/imageView"
    android:layout_centerHorizontal="true" />

<SearchView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/searchView"
    android:layout_below="@+id/imageView"
     />

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:id="@+id/imageView3"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="#ffdedede" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="EVENTS"
    android:id="@+id/button2"
    android:layout_alignBottom="@+id/imageView3"
    android:layout_toLeftOf="@+id/button3"
    android:layout_toStartOf="@+id/button3"
    android:layout_centerHorizontal="true"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="STAFF"
    android:id="@+id/button3"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/button"
    android:layout_toEndOf="@+id/button" />


</RelativeLayout>

正如我之前提到的,文本视图(文本视图本身位于不同的 xml 中)正在动画,但实际的列表视图不是。我已经尝试将片段更改为活动以消除视图/布局充气器。不知道还有什么可以尝试的。

[编辑 1] 这是 Android SDK 动画吗?这是来自 JazzyListView 库示例应用程序的图像...我的印象是 jazzylistview 也为列表视图设置了动画,否则有什么意义???

4

2 回答 2

1

Animation ofJazzyListView为其项目设置动画,但不为其自身设置动画。如果要为 a 设置动画,恐怕JazzyListView必须使用 提供的动画。Android SDK

于 2015-04-21T02:01:46.053 回答
1

要在 ListView 中添加动画,首先需要定义一个包含动画的 XML。在我的例子中,我创建了一个 fade_in.xml。您需要将此文件放在 res->anim->fade_in.xml 文件夹中

/res/anim/fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" />
</set>

然后,我创建了一个从 BaseAdapter 派生的类,以便我可以覆盖 getView 函数,并且可以在其中插入动画代码。

@Override
public View getView(int i, View view, ViewGroup viewGroup)
{
  View view = inflater.inflate(R.layout.task_item_large_one_line, null);
  ...
   Animation animation = AnimationUtils.loadAnimation(mainActivity, R.anim.fade_in);
   animation.setStartOffset(i*500);
   view.startAnimation(animation); 
  return view;
}
于 2015-04-21T02:50:31.770 回答