android控件旋转
㈠ android制作一个可以旋转textview怎么实现
android制作一个可以旋转textview需要用到补间动画,然后用textview调用该补间动画。在andorid studio中实现步骤如下。
1、首先在一个layout布局中创建一个textView控件,并定义id。代码如下:
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
2、然后创建anim文件,在然后文件中创建一个xml文件,文件中为tv_rotate。文件内容如下。
运行之后textView就可以旋转了。
㈡ Android 旋转动画
java"><rotate
android:fromDegrees="45"//起始旋转的角度
android:toDegrees="89"//结束选装后的角度
android:ration="500"//执行时间为500ms
android:pivotX="50%"//距离控件左边缘50%
android:pivotY="50%"//距离控件上边缘50%(与上边结合就是控件中心)
android:fillEnabled="true"
android:fillAfter="true"//动画执行完后停留在执行完的状态
/>
—————————————————————————————————————————
当然也可以通过代码用animation实现
好久没写,应该是
RotateAnimationanimation=newRotateAnimation(0f,45f,Animation.RELATIVE_TO_SELF,
0.5f,Animation.RELATIVE_TO_SELF,0.5f);
animation.setDuration(500);
view.setAnimation(animation);
㈢ android侧边菜单栏怎么实现旋转效果
是通过HorizontalScrollView这个控件实现的。
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/munu_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="60dp"
android:orientation="horizontal" >
<!-- view1 -->
<!-- view2 -->
<!-- view3 -->
<!-- view4 -->
</LinearLayout>
</HorizontalScrollView>
㈣ 如何使控件或者layout旋转180度
控件旋转:将android:rotation="180"写在layout下的.xml文件中对应的控件里
layout旋转:将android:screenOrientation="landscape"写在AndroidManifest.xml文件中对应的Activity里
㈤ android下,如何实现动画效果那样修改控件的宽高
创建一个线程修改控件大小相关数据,handler设置控件LayoutParmas
㈥ android RotateAnimation怎样设置旋转中心点
xml设置
android:fromDegrees="0" // 设置动画开始时的角度
android:toDegrees="+350" // 设置动画结束时的旋转角度
android:pivotX="50%" // 设置动画相对于控件的 x 坐标的位置
android:pivotY="50%" // 设置动画相对于控件的 y 坐标的位置
代码设置
final RotateAnimation animation =new RotateAnimation(0f,360f,Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF,0.5f);
主要是x,y的坐标为中心点
㈦ android开发中如何旋转布局
楼主你好,这个可以通过动画来达到这个效果的,代码如下:
只要把您的layout对象传进去就行了
public void showAnimation(View mView)
{
final float centerX = mView.getWidth() / 2.0f;
final float centerY = mView.getHeight() / 2.0f;
//这个是设置需要旋转的角度,我设置的是180度
RotateAnimation rotateAnimation = new RotateAnimation(0, 180, centerX,
centerY);
//这个是设置通话时间的
rotateAnimation.setDuration(1000*3);
rotateAnimation.setFillAfter(true);
mView.startAnimation(rotateAnimation);
}
㈧ 求助,怎么用android实现控件的3D立体旋转效果
实现水平滑动,所以可在手势抬起的时候进行判断并处理,是滑动显得流畅,代码如下:
packagecom.example.rotation3dview;
importandroid.content.Context;
importandroid.graphics.Camera;
importandroid.graphics.Canvas;
importandroid.graphics.Matrix;
importandroid.util.AttributeSet;
importandroid.view.MotionEvent;
importandroid.view.VelocityTracker;
importandroid.view.View;
importandroid.view.ViewDebug.HierarchyTraceType;
importandroid.view.ViewGroup;
importandroid.widget.ImageView;
importandroid.widget.Scroller;
{
privateintmCurScreen=1;
//滑动的速度
privatestaticfinalintSNAP_VELOCITY=500;
;
privateintmWidth;
privateScrollermScroller;
privateCameramCamera;
privateMatrixmMatrix;
//旋转的角度,可以进行修改来观察效果
privatefloatangle=90;
publicRote3DView(Contextcontext,AttributeSetattrs){
super(context,attrs);
mScroller=newScroller(context);
mCamera=newCamera();
mMatrix=newMatrix();
initScreens();
}
publicvoidinitScreens(){
ViewGroup.LayoutParamsp=newViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
for(inti=0;i<3;i++){
this.addView(newImageView(this.getContext()),i,p);
}
((ImageView)this.getChildAt(0)).setImageResource(R.drawable.page1);
((ImageView)this.getChildAt(1)).setImageResource(R.drawable.page2);
((ImageView)this.getChildAt(2)).setImageResource(R.drawable.page3);
}
@Override
protectedvoidonLayout(booleanchanged,intl,intt,intr,intb){
intchildLeft=0;
finalintchildCount=getChildCount();
for(inti=0;i<childCount;i++){
finalViewchildView=getChildAt(i);
if(childView.getVisibility()!=View.GONE){
finalintchildWidth=childView.getMeasuredWidth();
childView.layout(childLeft,0,childLeft+childWidth,childView.getMeasuredHeight());
childLeft+=childWidth;
}
}
}
@Override
protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec){
super.onMeasure(widthMeasureSpec,heightMeasureSpec);
finalintwidth=MeasureSpec.getSize(widthMeasureSpec);
finalintwidthMode=MeasureSpec.getMode(widthMeasureSpec);
if(widthMode!=MeasureSpec.EXACTLY){
thrownewIllegalStateException("仅支持精确尺寸");
}
finalintheightMode=MeasureSpec.getMode(heightMeasureSpec);
if(heightMode!=MeasureSpec.EXACTLY){
thrownewIllegalStateException("仅支持精确尺寸");
}
finalintcount=getChildCount();
for(inti=0;i<count;i++){
getChildAt(i).measure(widthMeasureSpec,heightMeasureSpec);
}
scrollTo(mCurScreen*width,0);
}
privatefloatmDownX;
@Override
publicbooleanonTouchEvent(MotionEventevent){
if(mVelocityTracker==null){
mVelocityTracker=VelocityTracker.obtain();
}
//将当前的触摸事件传递给VelocityTracker对象
mVelocityTracker.addMovement(event);
floatx=event.getX();
switch(event.getAction()){
caseMotionEvent.ACTION_DOWN:
if(!mScroller.isFinished()){
mScroller.abortAnimation();
}
mDownX=x;
break;
caseMotionEvent.ACTION_MOVE:
intdisX=(int)(mDownX-x);
mDownX=x;
scrollBy(disX,0);
break;
caseMotionEvent.ACTION_UP:
=mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000);
intvelocityX=(int)velocityTracker.getXVelocity();
if(velocityX>SNAP_VELOCITY&&mCurScreen>0){
snapToScreen(mCurScreen-1);
}elseif(velocityX<-SNAP_VELOCITY&&mCurScreen<getChildCount()-1){
snapToScreen(mCurScreen+1);
}else{
snapToDestination();
}
if(mVelocityTracker!=null){
mVelocityTracker.recycle();
mVelocityTracker=null;
}
break;
}
returntrue;
}
@Override
publicvoidcomputeScroll(){
if(mScroller.computeScrollOffset()){
scrollTo(mScroller.getCurrX(),mScroller.getCurrY());
postInvalidate();
}
}
publicvoidsnapToDestination(){
setMWidth();
finalintdestScreen=(getScrollX()+mWidth/2)/mWidth;
snapToScreen(destScreen);
}
publicvoidsnapToScreen(intwhichScreen){
whichScreen=Math.max(0,Math.min(whichScreen,getChildCount()-1));
setMWidth();
intscrollX=getScrollX();
intstartWidth=whichScreen*mWidth;
if(scrollX!=startWidth){
intdelta=0;
intstartX=0;
if(whichScreen>mCurScreen){
setPre();
delta=startWidth-scrollX;
startX=mWidth-startWidth+scrollX;
}elseif(whichScreen<mCurScreen){
setNext();
delta=-scrollX;
startX=scrollX+mWidth;
}else{
startX=scrollX;
delta=startWidth-scrollX;
}
mScroller.startScroll(startX,0,delta,0,Math.abs(delta)*2);
invalidate();
}
}
privatevoidsetNext(){
intcount=this.getChildCount();
Viewview=getChildAt(count-1);
removeViewAt(count-1);
addView(view,0);
}
privatevoidsetPre(){
intcount=this.getChildCount();
Viewview=getChildAt(0);
removeViewAt(0);
addView(view,count-1);
}
privatevoidsetMWidth(){
if(mWidth==0){
mWidth=getWidth();
}
}
}
实现立体效果,添加如下代码:
/*
*当进行View滑动时,会导致当前的View无效,该函数的作用是对View进行重新绘制调用drawScreen函数
*/
@Override
protectedvoiddispatchDraw(Canvascanvas){
finallongdrawingTime=getDrawingTime();
finalintcount=getChildCount();
for(inti=0;i<count;i++){
drawScreen(canvas,i,drawingTime);
}
}
publicvoiddrawScreen(Canvascanvas,intscreen,longdrawingTime){
//得到当前子View的宽度
finalintwidth=getWidth();
finalintscrollWidth=screen*width;
finalintscrollX=this.getScrollX();
//偏移量不足的时
if(scrollWidth>scrollX+width||scrollWidth+width<scrollX){
return;
}
finalViewchild=getChildAt(screen);
finalintfaceIndex=screen;
finalfloatcurrentDegree=getScrollX()*(angle/getMeasuredWidth());
finalfloatfaceDegree=currentDegree-faceIndex*angle;
if(faceDegree>90||faceDegree<-90){
return;
}
finalfloatcenterX=(scrollWidth<scrollX)?scrollWidth+width
:scrollWidth;
finalfloatcenterY=getHeight()/2;
finalCameracamera=mCamera;
finalMatrixmatrix=mMatrix;
canvas.save();
camera.save();
camera.rotateY(-faceDegree);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX,-centerY);
matrix.postTranslate(centerX,centerY);
canvas.concat(matrix);
drawChild(canvas,child,drawingTime);
canvas.restore();
}
㈨ android仿饿了么加入购物车旋转控件动画按钮
这个二维控件不支持,你可以对按钮进行动画式的先变窄再变宽,并进行颜色变换,从而达到模拟立体翻转的效果。更推荐的方法是直接使用WPF的3D功能,制作长方形,并在正反面都使用VisualBrush,而VisualBrush绑定到控件,使得这个长方形看起来像一个立体的按钮,并且拥有正反面,最后使用Transform3D派生的Rotetransform3D进行真正意义上的旋转。