由于某些原因,列表视图不是动画,只有文本视图是动画。我有一种感觉,这与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中)是动画的,但实际的列表视图不是。我已经尝试将片段更改为activity,以消除视图/布局膨胀。不知道还能尝试什么。
编辑1这是Android SDK动画吗?这是一张来自JazzyListView库示例应用程序的图像...我的印象是jazzylistview也为listview添加了动画,否则有什么意义呢?

发布于 2015-04-21 10:01:46
JazzyListView的动画会对其项目进行动画处理,但不会对其本身进行动画处理。如果你想给JazzyListView添加动画效果,恐怕你必须使用Android SDK提供的动画效果。
发布于 2015-04-21 10:50:32
要在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;
}https://stackoverflow.com/questions/29761478
复制相似问题