问题描述
这可能是一个愚蠢的问题。
我知道我可以在包装一个ViewFlipper ListView的,但我们可以在ViewFlipper换个人的ListView项目?例如,最新的Twitter的应用程序使用一个ListView显示推文。它还允许你通过滑动鸣叫闪开露出下面的设置选项图标设置上单个项目的设置。这是一个自定义的实现还是我们必须创建一个使用ListView和ViewFlipper类似的东西的能力吗?谢谢,任何的建议是AP preciated!
我花了一些这方面的时间,得到了ListView控件来显示通过ViewFlipper其他内容。然而,认为似乎只在ListView中的最后一个项目炫。我如何获得每个项目点击时翻转?下面是一些code:
row.xml
<?XML版本=1.0编码=UTF-8&GT?;
< ViewFlipper的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /脚蹼的android:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< TextView的机器人:ID =@ + ID /的TopText的android:layout_width =FILL_PARENT
机器人:layout_height =0dip机器人:layout_weight =1
机器人:重力=center_vertical/>
< TextView的机器人:ID =@ + ID / bottomtext的android:layout_width =FILL_PARENT
机器人:layout_height =0dip机器人:layout_weight =1
机器人:重力=center_vertical/>
< / ViewFlipper>
的main.xml
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直的android:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
< ListView的机器人:ID =@ ID /安卓名单的android:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>
< / LinearLayout中>
ListActivityView.java - 扩展ListActivity
...
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
...
} @覆盖
保护无效onListItemClick(ListView中升,视图V,INT位置,长的id){
super.onListItemClick(L,V,位置ID);
//无所谓点击哪条线路
//只在ListView中的最后一项显示bottomText
viewFlipper.showNext();
}
ListingAdapter.java - 扩展ArrayAdapter
@覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
视图V = convertView; 如果(V == NULL){
LayoutInflater VI =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
V = vi.inflate(R.layout.row,NULL); viewFlipper =(ViewFlipper)v.findViewById(R.id.flipper);
}
如果我得到你的问题正确的 - 你可以使用 ViewFlipper
定义成一排的布局里面你的清单,初始化它呈现相应的视图,当你喜欢的方式。
This is probably a stupid question.
I know I can wrap a ListView in ViewFlipper, but can we wrap individual ListView Items in a ViewFlipper? For instance, the latest Twitter app uses a ListView to display Tweets. It also allows you to set settings on individual items by sliding the tweet out of the way exposing the setting option icons below. Is this a custom implementation or do we have the ability to create something similar using ListView and ViewFlipper? Thanks, any advice is appreciated!
I've spent some time on this and got the ListView to display additional content via the ViewFlipper. However, the view only seems to "flip" on the last item in the ListView. How do I get each item to flip when clicked? Here's some code:
row.xml
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flipper" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/toptext" android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_weight="1"
android:gravity="center_vertical" />
<TextView android:id="@+id/bottomtext" android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_weight="1"
android:gravity="center_vertical" />
</ViewFlipper>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@id/android:list" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
ListActivityView.java - extends ListActivity
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// doesn't matter which line is clicked
// only the last item in the ListView displays the bottomText
viewFlipper.showNext();
}
ListingAdapter.java - extends ArrayAdapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
viewFlipper = (ViewFlipper) v.findViewById(R.id.flipper);
}
If I am getting your question correct - you can use ViewFlipper
inside a layout that defines a row in your list and init it the way you like when rendering corresponding view
这篇关于的Android +使用ViewFlipper翻转一个ListView中的单个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!