Android ListView - 从右侧滑入子视图?
我有一个列表视图。当我在 ListView 中选择一个项目时,我希望有一个子视图从右侧滑入,就像在许多应用程序中那样。
我一直在寻找关于这个主题的教程,但我正在旋转。也许 Android 使用与“Subview”不同的术语?
这就是我最终要做的:
为子视图创建一个新类
使用
在
标签内将其添加到主类(“lv”是 ListView)
<块引用>lv.setOnItemClickListener(new OnItemClickListener() {
公共无效onItemClick(AdapterView父级, 查看视图,int位置,长id){Intent myIntent = new Intent(view.getContext(),SubView.class); startActivityForResult(myIntent, 0); }
});
I have a ListView. When I select an item in the ListView, I would like to have a Subview slide in from the right, the way that it does in many Apps.
I have been searching for tutorials on this topic but am spinning my wheels. Maybe Android uses a term different than "Subview" ?
Here's what I ended up doing:
Create a New Class for the SubView
Add the Subview class to the Manifest with
<activity android:name=".SubViewClassName" />
inside the<application>
tagAdd this to the main Class ("lv" is the ListView)
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent,
View view,int position, long id) {Intent myIntent = new Intent(view.getContext(),SubView.class); startActivityForResult(myIntent, 0); }
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最简单的事情就是让第二个
ListView
位于单独的Activity
中。如果用户启用了交互动画(这是默认设置),那么您的第二个ListView
将从右侧滑入。The simplest thing is to have your second
ListView
be in a separateActivity
. If the user has inter-activity animations enabled (and that is the default), then your secondListView
will slide in from the right.为此,您需要使用 ViewFlipper
以下是设置 main.xml 文件的方法:
在本例中,两个视图的 xml 文件是 home_screen 和 info_screen。您可以随意命名它们。
在您的代码中,您需要将其放在 onCreate() 方法中:
此外,您还需要在 onCreate() 方法下面使用这些方法。
当你准备好后,只需使用
For this to work you will need to use a ViewFlipper
Here is how you would set up your main.xml file:
The xml files for the two views are home_screen and info_screen in this case. You can name them anything you'd like.
In your code you will need to place this in your onCreate() method:
Additionally you need these methods below your onCreate() method.
And when you're ready simply use
也许我错了,但您可以在此子活动中使用
overridePendingTransition
吗?在您的主要活动中:
或您想要的任何代码。主要的事情是在您的子活动(和子视图)中,如
MySubActivity
中:以下是
res/anim
文件夹中的动画文件Enter_from_right.xml
exit_to_left.xml
希望有所帮助。
Maybe I'm wrong, but you can use an
overridePendingTransition
in this sub activity ?In your main activity :
Or whatever code you want. The main thing is in your subactivity (and subview) like in
MySubActivity
:Here are the animation files in the
res/anim
folderenter_from_right.xml
exit_to_left.xml
Hope that helps.
只是对 Ryan 的回应(使用 ViewFlipper)的一小部分补充:
Just small addition to Ryan's response (Using ViewFlipper):