2016-04-27 84 views
0

我有一個要求,當我從服務器收到一個值時,需要動態輪轉動一個輪子。Android:圓形菜單動態旋轉

我使用的是WheelMenu library,它可以是fou。

wheelMenu.setAlternateTopDiv(int); 使用這一行代碼在輪子旋轉方面沒有任何區別。

這是我想旋轉自動輪。

enter image description here

在此先感謝。

回答

2

嗨我下載了庫並閱讀文檔。事情是圖書館不做你想做的事情。方法wheelMenu.setAlternateTopDiv(int)只是改變車輪的參考選擇。

如果您想自動旋轉圖像,請使用動畫並旋轉一定角度以達到您想要的位置。

編輯:

你可以試試這個代碼,打開圖像,每次你點擊該按鈕,但沒有動畫90度。嘗試一下,讓我知道它是否你想要的。

public class MainActivity extends AppCompatActivity { 

private ImageView imageView; 
private Button button; 
private float rotation = 0; 

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

    imageView = (ImageView) findViewById(R.id.image); 
    button = (Button) findViewById(R.id.button); 

    button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      rotation = rotation + 90; 
      imageView.setRotation(rotation); 
     } 
    }); 
} 

@Override 
protected void onDestroy() { 
    super.onDestroy(); 

} 
} 

佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.gohidoc.realmtest.MainActivity"> 

<ImageView 
    android:id="@+id/image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/wheel"/> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="turn"/> 

</RelativeLayout> 

圖像:

Wheel

+0

是的,我需要這樣做。你能幫我嗎我該怎麼做? –

+1

@RobinRoyal你可以試試我編輯過的內容,並告訴我你是否需要更多動畫或其他用例的幫助 – Chami

+1

@RobinRoyal任何消息? – Chami