- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想创建 ViewPager
,它在滑动时围绕它的 getWidth()
和 getHeight()
轴旋转。我试过了,但所有这些转换只能通过垂直和水平的各种效果实现。
有什么方法或提示可以开发这种ViewPager
吗?
EDIT- 解释它会是什么样的轮换
Axis - getWidth
, getHeight
应该是枢轴点,一旦我滑动它应该旋转,对于下一页它应该从 (0, getHeight) 轴旋转。为了简化,考虑这个简单的场景 -
ViewPager
应该从第 1 页旋转到第 2 页。ViewPager
应该从第 1 页旋转到第 4 页。getWidth
、getHeight
。因此,对于下一页,它将始终是 0
,getHeight
作为轴,而对于上一页,它将始终是 getWidth
,0
作为轴。最佳答案
更新据我所知,你想要这样的过渡。如下所示,实现了 ViewPager.PageTransformer
。
这是 ViewPager.PageTransformer
类:
public class RotationCircleTransformer implements ViewPager.PageTransformer {
public RotationCircleTransformer() {
}
public void transformPage(View view, float position) {
int pageWidth = view.getWidth();
int pageHeight = view.getHeight();
view.setPivotX((float) pageWidth);
view.setPivotY((float) pageHeight);
if (position < -1) { //[-infinity,1)
//off to the left by a lot
view.setRotation(0);
view.setAlpha(0);
} else if (position <= 1) { //[-1,1]
view.setTranslationX((-position) * pageWidth); //shift the view over
view.setRotation(position * (90)); //rotate it
// Fade the page relative to its distance from the center
view.setAlpha(Math.max(1, 1 - Math.abs(position) / 3));
} else { //(1, +infinity]
//off to the right by a lot
view.setRotation(0);
view.setAlpha(0);
}
}
}
background_quarter.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:height="300dp" android:width="300dp"/>
<solid android:color="#00F"/>
<corners android:topLeftRadius="300dp" android:topRightRadius="0dp" android:bottomRightRadius="0dp" android:bottomLeftRadius="0dp"/>
</shape>
activity_circle_pager.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_gravity="center"
android:layout_width="300dp"
android:layout_height="300dp" />
</FrameLayout>
fragment_content.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="300dp"
android:id="@+id/bg"
android:background="@drawable/background_quarter">
<TextView
android:id="@+id/text"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="40dp"
android:textColor="@android:color/white"
android:text="" />
</FrameLayout>
CircleFragment.class
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
public class CircleFragment extends Fragment {
private String typeString;
public CircleFragment() {
}
public static CircleFragment newInstance(String type) {
CircleFragment fragment = new CircleFragment();
Bundle args = new Bundle();
args.putString("type", type);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
typeString = getArguments().getString("type","1");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_content, container, false);
;
TextView text = (TextView) view.findViewById(R.id.text);
FrameLayout bg = (FrameLayout) view.findViewById(R.id.bg);
switch (typeString) {
case "1":
bg.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.background_quarter));
break;
case "2":
bg.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.background_quarter));
break;
case "3":
bg.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.background_quarter));
break;
case "4":
bg.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.background_quarter));
break;
}
text.setText(typeString);
return view;
}
}
CirclePagerActivity.class
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
public class CirclePagerActivity extends AppCompatActivity {
ViewPager mPager;
CirclePagerAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_circle_pager);
mPager = (ViewPager) findViewById(R.id.pager);
List<Fragment> fragments = new ArrayList<>();
fragments.add(ContentFragment.newInstance("1"));
fragments.add(ContentFragment.newInstance("2"));
fragments.add(ContentFragment.newInstance("3"));
fragments.add(ContentFragment.newInstance("4"));
mAdapter = new CirclePagerAdapter(getSupportFragmentManager(), fragments);
mPager.setAdapter(mAdapter);
mPager.setPageTransformer(true, new RotationCircleTransformer());
}
@Override
protected void onDestroy() {
super.onDestroy();
}
static class CirclePagerAdapter extends FragmentStatePagerAdapter {
List<Fragment> mFrags = new ArrayList<>();
public CirclePagerAdapter(FragmentManager fm, List<Fragment> frags) {
super(fm);
mFrags = frags;
}
@Override
public Fragment getItem(int position) {
int index = position % mFrags.size();
return mFrags.get(index);
}
@Override
public int getCount() {
return Integer.MAX_VALUE;
}
}
}
如果没有找到合适的ViewPager
变换动画,可以自己实现ViewPager.PageTransformer
There is大量信息和多个示例。
还有 here您可以找到有用的教程。
你能更详细地解释一下这部分吗?我会根据您的解释更新我的答案(视觉解释更好)。
rotates around it's getWidth() and getHeight() axis.
关于android - 具有旋转变换的 ViewPager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43950802/
我正在寻找一种简单的解决方案来将对象从一个地方移动和缩放到另一个地方。 我做了一个JSfiddle用这个代码。问题是我需要它在某个时刻停止变小。所以它有一个最小尺寸,另一个问题是我希望它既缩小又向左移
我正在尝试通过沿 x 轴上下翻转(180 度)来为悬停时的图像设置动画。 就像here 除非我出于某种原因无法让它工作。 img { transition:all 2s ease-in-out
我想实例化一个 slider 约束,它允许 body 在 A 点和 B 点之间滑动。 为了实例化约束,我指定了两个物体进行约束,在这种情况下,一个动态物体被约束到静态世界,比如滑动门。 第三个和第四个
我想使用此功能旋转然后停止在特定点或角度。现在该元素只是旋转而不停止。代码如下: $(function() { var $elie = $("#bkgimg");
我正在尝试使用 CATransform3D 向 View 添加透视图。目前,这就是我得到的: 这就是我想要得到的: 我很难做到这一点。我完全迷失在这里。这是我的代码: CATransform3D t
我编写了一个图形用户界面,用户可以在其中在 (640x480) 窗口中绘制内容。它使该绘图成为一组存储在 Vector 数组中的点。 现在,我如何将这些点集平移到原点(0,0 窗口左上角)或将其放在指
我的应用程序中有两张图像相互叠加,分别表示为 foreground 和 background。对于这两个,我都使用 background-attachment: fixed 来确保图像始终彼此完全相同
如何在不损失质量的情况下应用旋转变换?我试过添加 translateZ(0) 但它无济于事。这是例子: svg { background-color: rgb(93, 193, 93); }
我有一个 div,我试图在悬停时缩放它(只是 Y)。问题是它在没有过渡的情况下运行良好。当我使用过渡时,div 在顶部缩放一点然后下降,检查 fiddle 。问题是如何防止 div 那样缩放?我希望它
我正在尝试使用 transform: scale 图像网格 http://movies.themodern-nerd.com/genre .从左向右滚动时它工作正常,悬停的图像将停留在其他图像之上,但
我正在查看 CSS3 Transform 并且想要一个既倾斜又旋转的盒子。 我试过使用: transform:rotate(80deg); -moz-transform:rotate(80deg);
当用户在图像父元素上执行 mousemove 时,我试图在 img 上添加平滑移动效果(此处为 .carousel-img)但我无法正常运行它。 我做错了什么? $('.carousel-img').
我有 div 元素在其他 div 元素中垂直对齐。 我使用以下方法对齐它们:position: relative;变换:翻译Y(-50%);顶部:50%。这很好用。 我现在想缩放元素(使用 jQuer
我在这个 fiddle 中使用 RotateX 后创建了 3D 效果: http://jsfiddle.net/vEWEL/11/ 但是,我不确定如何在这个 Fiddle 中的红色方 block 上实
使用 transform: scale(x.x) 而不是使用 width 和 height 属性进行传统的调整大小有什么缺点吗?缩放会产生质量较低的图像或其他什么吗? 最佳答案 Scale 生成总体上
我在一个点上有一个对象,比如相对于原点的 x、y、z。 我想对点应用一些变换,比如旋转和平移,并在变换后的点渲染对象。我正在使用 glTranslatef() 和 glRotatef() 函数。它看起
有没有办法将转换应用到插入了 :before 的元素上? 以下方法无效,但我愿意接受其他解决方案。 .itemclass:before { content: "➨"; transform:
我找到了这个:width/height after transform 和其他几个,但没有什么不是我正在寻找的。我想要的是将某些东西缩放到其大小的 50%(当然还有漂亮的动画过渡)并让页面布局重新调整
我想使用变换为元素位置设置动画。我怎么能在这个翻译中添加一些曲线(没什么特别的,只是不是一条完整的直线)?对于 jquery,我会使用效果很好的 easeInSine。 var a = documen
我试着写一个 TransformMesh功能。该函数接受一个 Mesh对象和 Matrix目的。这个想法是使用矩阵来转换网格。为此,我锁定了顶点缓冲区,并在每个顶点上调用了 Vector3::Tran
我是一名优秀的程序员,十分优秀!