【问题标题】:Android image overlay [closed]Android图像覆盖[关闭]
【发布时间】:2016-04-26 12:40:02
【问题描述】:

Android Image 想开发这种类型的屏幕。 当用户单击第一个图像时,该图像移动到第三个位置,并且 第二个图像进入第一个位置。图像循环必须 是连续的。我正在经历大量的搜索,如 viewpager 边缘效果、hollo 效果、viewpager 叠加,但没有找到我的解决方案。任何帮助将不胜感激。

【问题讨论】:

  • 你可能需要多窄,我刚刚发布了我想要的屏幕。

标签: android android-layout android-studio android-animation


【解决方案1】:

使用此链接可能会对您有所帮助............

链接:-http://www.devexchanges.info/2015/11/making-carousel-layout-in-android.html

或者使用这个xml文件........

<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="match_parent">

          <ImageView
        android:id="@+id/image3"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:src="@drawable/first"
        android:scaleType="fitXY"
        android:layout_gravity="center"/>
    <ImageView
        android:id="@+id/image2"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:src="@drawable/today"
        android:scaleType="fitXY"
        android:layout_gravity="center"/>

    <ImageView
        android:id="@+id/image1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:src="@drawable/all_stories"
        android:scaleType="fitXY"
        android:layout_gravity="center"/>
    </FrameLayout>

</LinearLayout>

并使用此代码......

 int images[] = {R.drawable.all_stories, R.drawable.today, R.drawable.first}, temp;

在 Activity 和所有方法之外输入这个。

图像中的代码onclick(View view)方法.....

 if (view.getId() == R.id.image2) {
            temp = images[0];
            images[0] = images[1];
            images[1] = images[2];
            images[2] = temp;
            image1.setImageResource(images[0]);
            image2.setImageResource(images[1]);
            image3.setImageResource(images[2]);
        }


        if (view.getId() == R.id.image3) {
            temp = images[0];
            images[0] = images[2];
            images[2] = temp;
            image1.setImageResource(images[0]);
            image2.setImageResource(images[1]);
            image3.setImageResource(images[2]);
        }

它的运行我检查了它......

享受编码.....

【讨论】:

  • 看起来找到了我想要的,但必须先实现。
  • 按照链接中的说明或查看编辑答案。
  • 好的。我一会儿再联系你。
  • 在哪里应用点击事件?
  • 只是在活动中实现 OnClickListner。并设置 image3.setOnClickListner(this); image2.setOnClickListner(this);并重写 OnClick(View view) 方法并将代码放入其中。
【解决方案2】:

只需创建一个 Framelayout 并将所有图像放入其中。决定在 OnClickListener 中做什么(设置可见性)。

【讨论】:

  • 应该可以处理 100 张图片?
  • 然后以编程方式代替静态layout.xml。实际上,您不需要 FrameLayout 。只需在单击 ImageView 时更新图像源。您可以将图像资源 ID 存储在列表或堆栈中。所以应该很容易...
  • 你检查了我的安卓图像吗。
  • 是的,但我不确定你是否需要这种叠加效果...
  • 是的,我需要溢出。
猜你喜欢
  • 2018-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-19
  • 1970-01-01
  • 2015-05-25
  • 1970-01-01
  • 2020-10-17
相关资源
最近更新 更多