Android 水平滚动视图还是旋转木马?

Android 水平滚动视图还是旋转木马?,android,android-viewpager,android-animation,android-imageview,Android,Android Viewpager,Android Animation,Android Imageview,我想创建一个水平滚动视图,但其中包含一些“效果”,比如这样或这样。问题是我不知道我要用多少东西;我从API获得ImageView,因此它应该是动态的。如果选择了它,如何使它在下面的TextView中变得更大?我在SO上找到的最接近的例子是。这正是我需要的,但我已经测试了给出的答案,它对我不起作用。。。但问题中的图像正是我想要的。有谁能指导我这样做吗 假设我将使用5ImageView对其进行测试,仅用于测试,因此如何动态添加这些ImageView的示例对我也很有用 另一个例子是,但不同的是,我想添

我想创建一个
水平滚动视图
,但其中包含一些“效果”,比如这样或这样。问题是我不知道我要用多少东西;我从API获得
ImageView
,因此它应该是动态的。如果选择了它,如何使它在下面的
TextView
中变得更大?我在SO上找到的最接近的例子是。这正是我需要的,但我已经测试了给出的答案,它对我不起作用。。。但问题中的图像正是我想要的。有谁能指导我这样做吗

假设我将使用5
ImageView
对其进行测试,仅用于测试,因此如何动态添加这些
ImageView
的示例对我也很有用

另一个例子是,但不同的是,我想添加一些效果对选定的喜欢使它更大或什么

编辑 我想获得一个示例,说明如何使用布局(适配器)创建自定义的HorizontalScrollView,最重要的是,如果可能的话,为单击的视图添加一个效果,我需要适配器,因为我当然需要单击该项。我认为我应该使用@UncaughtException的RecycleView对我说,因为我不知道我将获得多少图像,我必须在我的应用程序上添加这些图像,所以我认为这是解决方案


这将是和之间的混合步骤1:

以水平方向显示图像

第二步:

将类应用于单击的项以放大它。这可以在
ViewPager
PagerAdapter
instantiateItem()
方法中完成

此外,还有一些现成的开源小部件,如和。您可能想查看源代码,看看它们是如何工作的

编辑:

首先,关于如何处理未知数量的图像的问题,您应该认识到,在所有此类小部件(
ListView
GridView
ViewPager
等)中,来自API的对象数在一开始总是未知的,即在接收到API响应时就知道了。因此,如果您首先以正常方式实现一个
ViewPager
,您将看到它是如何处理的。基本上,您必须使用
适配器
和模型对象来填充
查看页面
列表视图
。API响应将是JSON或XML,解析后,您将知道项目的确切数量

因此,我认为您应该首先以正常方式实现
ViewPager
。这方面有很多例子。两个有趣的是和。它们对于您的案例来说很有趣,因为它们还包含如何放大图像的示例代码

现在进入第二个问题:我们如何放大图像。为此,一种方法是使用
ScaleAnimation
类。例如,假设要围绕图像中心将图像放大100%:

ScaleAnimation scaleAnimation =  new ScaleAnimation(1.0f, 1.5f,
                                                    1.0f, 1.5f,
                                                        Animation.RELATIVE_TO_SELF, 0.5f,
                                                        Animation.RELATIVE_TO_SELF, 0.5f);

scaleAnimation.setDuration(200);
scaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator());

imageView.startAnimation(scaleAnimation);
我会在
ViewPager
PagerAdapter
instantiateItem()方法中的图像上使用此代码。这应该行得通。或者,您可以在前面两个示例中的一个中尝试缩放动画方法

恐怕您必须尝试使用这些示例作为指导创建一个工作项目。然后我们可以进一步讨论您面临的任何其他问题。我相信这很容易做到,我知道你能做到。最好的

编辑2:


根据你给出的两个例子,你见过和吗?这就是你要找的吗?它是否使您更接近于解决问题?

在您的情况下,您肯定可以使用
查看页面
,但如果我是您,我会使用
线性布局管理器
进行
回收视图
,其方向设置为
水平
,因此您不需要
水平滚动视图
,使用
RecyclerView
您还将获得您正在寻找的
适配器

现在,为了缩放
或在
上显示一些其他效果,请单击以将其与其他视图区分开来,您可以为该特定视图设置动画

我已经为此编写了一些演示代码,在这里发布了所需的文件,如果这是您想要的,请告诉我

活动

/**
  * Created by Satyen on 10/27/15.
  **/
public class SlidingDrawerActivity extends Activity {

   RecyclerView rcyList;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_scroll_list);

        rcyList = (RecyclerView) findViewById(R.id.rcyList);

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rcyList.setLayoutManager(layoutManager);

       /* rcyList.addItemDecoration(
                new DividerItemDecoration(this, null));*/
        MyRecyclerViewAdapter myRecyclerAdapter = new MyRecyclerViewAdapter(this);
        rcyList.setAdapter(myRecyclerAdapter);

    }


}
活动布局

<!-- layout_scroll_list.xml -->

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:layout_weight="1">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rcyList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@android:color/holo_blue_dark"
        android:paddingLeft="8dp"
        android:paddingRight="8dp" />

</FrameLayout>
</LinearLayout>
<!-- list_row.xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">

<RelativeLayout
    android:layout_width="80dp"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/thumbnail"
        android:layout_width="100dp"
        android:layout_height="80dp"
        android:layout_alignParentLeft="true"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/thumbnail"
        android:layout_centerHorizontal="true"
        android:text="dafdafda"
        android:textColor="#222"
        android:textSize="12sp" />

</RelativeLayout>

</LinearLayout>


要实施哪种解决方案?stackoverflow问题上的一个或其他示例中的一个lins@Blackbelt我指的是问题上贴的图片。这可以通过一个ViewPager实现。所以当我选择其中一个图片视图时,它会比其他的视图大吗?我可以用ViewPager来做吗?你应该用水平循环视图来做。我看到了allready,但是你知道我是否可以用这样的方法来做吗?我已经给出了上面的方法。。。如果你正确地应用它,那么我相信它会起作用……:)你知道我是否可以使用那些没有旋转的图像吗?我的意思是,这些图像像是旋转的,我想要它不旋转,绝对。。。我很惊讶没有其他人试图回答这个问题。。。我会尽快发布一个更好的答案…:)当然很快再和你谈谈……:)你搞定了!最后一件事我需要看看它是否有效,我需要
放大
动画。抱歉,你可以忽略这一行我们在代码中没有使用这一行,我正在编辑答案我应该如何使用这些图标,我的意思是这是来自API的调用,所以我需要根据需要填充它,明白吗?还有一件事,你们知道为什么我选择一个数据编号X,水平滚动,然后返回到它,它没有缩放?你们的意思是从url显示它们吗?如果我没有错,那么您可以使用
imageload
库,如
UniversalImageLoader
Picasso
以及

<!-- list_row.xml -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">

<RelativeLayout
    android:layout_width="80dp"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/thumbnail"
        android:layout_width="100dp"
        android:layout_height="80dp"
        android:layout_alignParentLeft="true"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/thumbnail"
        android:layout_centerHorizontal="true"
        android:text="dafdafda"
        android:textColor="#222"
        android:textSize="12sp" />

</RelativeLayout>

</LinearLayout>