當前位置:首頁 » 安卓系統 » android控制項旋轉

android控制項旋轉

發布時間: 2022-05-07 02:10:03

㈠ 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進行真正意義上的旋轉。

    熱點內容
    sqlserver建立視圖 發布:2025-05-14 13:11:56 瀏覽:483
    搭建httpsgit伺服器搭建 發布:2025-05-14 13:09:47 瀏覽:253
    新電腦拿回來我該怎麼配置 發布:2025-05-14 13:09:45 瀏覽:238
    視頻伺服器新建ftp用戶 發布:2025-05-14 13:03:09 瀏覽:225
    php花生 發布:2025-05-14 12:54:30 瀏覽:550
    java人才 發布:2025-05-14 12:29:10 瀏覽:649
    如何打開軟密碼 發布:2025-05-14 12:28:55 瀏覽:427
    七牛存儲待遇 發布:2025-05-14 12:27:20 瀏覽:422
    C語言a35a4a5 發布:2025-05-14 11:53:48 瀏覽:814
    android隱藏item 發布:2025-05-14 11:43:56 瀏覽:328