由于某种原因,列表视图不是动画,只有文本视图。我有一种感觉它与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>
正如我之前提到的textviews(textviews在不同的xml中自己)是动画,但实际的listview不是。我已经尝试将片段更改为活动以消除视图/布局inflater。不知道还有什么可以尝试。
[编辑1]这是Android SDK动画吗?这是来自JazzyListView库示例应用程序的图像...我的印象是jazzylistview也为listview设置了动画,否则有什么意义呢?
答案 0 :(得分:1)
JazzyListView
的动画动画其项目但不动画本身。如果您想为JazzyListView
制作动画,那么您恐怕必须使用Android SDK
提供的动画。
答案 1 :(得分:1)
要在ListView中添加动画,首先需要定义一个 包含动画的XML。在我的例子中,我创建了一个fade_in.xml。 您需要将此文件放在res-&gt; anim-&gt; 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;
}