我用以下代码得到了奇怪的结果:
iv = (ImageView) findViewById(R.id.iv);
iv.setImageResource(R.drawable.spinner_white_76);
Animation a = new RotateAnimation(0.0f, 360.0f,
Animation.RELATIVE_TO_SELF, iv.getDrawable()
.getIntrinsicWidth() / 2, Animation.RELATIVE_TO_SELF,
iv.getDrawable().getIntrinsicHeight() / 2);
a.setRepeatCount(-1);
a.setDuration(1000);
iv.startAnimation(a);
Run Code Online (Sandbox Code Playgroud)
什么是正确的方式来指定轴点(可绘制的中心)?
我想在Honeycomb ActionBar中添加一个不确定的进度条,这样每当用户按下"刷新"时,刷新图标会暂时变为不确定的进度条,直到任务完成.电子邮件应用程序已经这样做,但我无法弄清楚如何.
有什么建议?
如何显示Indeterminate ProgressBar何时Refresh按下按钮并在ActionBarSherlock刷新ViewGroup时再次显示刷新按钮?
更新1: 我在这里有一个不完整的答案.我正在提出一个问题的赏金,以便更多的开发人员可以帮助建立一个对将来有用的好答案.
我们如何显示Indeterminate ProgressBar如下图所示的图片
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
return true;
case R.id.searchIcon:
return true;
case R.id.startRefresh:
refreshItem = item;
refresh();
return true;
case R.id.stopRefresh:
if (refreshItem != null && refreshItem.getActionView() != null) {
refreshItem.getActionView().clearAnimation();
refreshItem.setActionView(null);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void refresh() {
if (FeedActivity.this != null) {
/*
* Attach a rotating ImageView to the refresh item as an ActionView
*/
LayoutInflater inflater = (LayoutInflater) FeedActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ImageView iv = (ImageView) inflater.inflate(
R.layout.refresh_action_view, …Run Code Online (Sandbox Code Playgroud) 我正在使用此问题的代码:ActionItem的动画图标来动画我的刷新ActionBarButton.它工作正常,除了风格似乎不正确.当我点击该项目时,它开始旋转,但只有在它"跳"几个像素之后.看起来ImageView风格与菜单项的风格不同.
该项定义如下:
<item
android:id="@+id/action_refresh"
android:orderInCategory="100"
android:icon="@drawable/ic_menu_refresh"
android:showAsAction="ifRoom"
<!-- added this myself, didn't have any effect -->
style="@android:style/Widget.ActionButton"
android:title="@string/action_refresh"/>
Run Code Online (Sandbox Code Playgroud)
之ImageView类的:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/action_refresh"
android:src="@drawable/ic_menu_refresh"
style="@android:style/Widget.ActionButton" />
Run Code Online (Sandbox Code Playgroud)
如何设置我的menuitem以匹配ImageView旋转,或者相反?
有没有办法在工具栏上设置默认的3垂直点菜单图标的动画?
我使用工具栏作为标准代码的操作栏:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Run Code Online (Sandbox Code Playgroud)
我也使用onCreateOptionsMenu内部活动的方法,我膨胀我的menu.xml文件,但我不知道如何获得更多控制自动创建的溢出图标.我最感兴趣的是如何引用菜单图标所以我可以为它设置动画.我不关心动画类型.它可以是一个简单的旋转动画
我试图理解菜单图标动画是否应该在新的Navigationview中工作,与动作项动画的工作方式相同,或者任何其他视图,在任何应用程序布局上使用.
下面的代码对我不起作用.我正在使用Android测试Android发布的代码示例来获取新的支持库.相同的动画代码在工具栏上很好地工作.还尝试了旧的动画API(紧随该链接:ActionItem的动画图标)
我想我错过了一些东西......
谢谢你.
码:
XML:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:background="@color/lightPrimaryColor">
<include layout="@layout/include_list_viewpager"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="@color/lightPrimaryColor"
app:headerLayout="@layout/nav_header"
app:theme="@style/menu_item_style"
app:menu="@menu/drawer_view"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
drawer_view:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:class="http://schemas.android.com/tools"
class:actionViewClass="android.widget.ProgressBar">
<group android:checkableBehavior="single"
android:id="@+id/drawer_menu">
<!-- <item
android:id="@+id/nav_my_lists"
android:title="@string/title_shopping_lists"
android:icon="@drawable/ic_event"
app:showAsAction="always"/> -->
<item
android:id="@+id/nav_examp_lists"
android:icon="@drawable/refresh1"
android:title="@string/example"
app:showAsAction="always"
android:layoutDirection="rtl"/>
<item
android:id="@+id/nav_split_lists"
android:title="@string/split"
android:icon="@drawable/refresh2"
app:showAsAction="always"
app:actionViewClass="android.widget.ImageView"/>
<item
android:id="@+id/nav_change_net"
android:title="@string/change"
android:icon="@drawable/refresh3"
app:showAsAction="always"
android:layoutDirection="rtl"/>
</group>
</menu>
Run Code Online (Sandbox Code Playgroud)
Java的:
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
menuItem.setChecked(true); …Run Code Online (Sandbox Code Playgroud) 我想将旋转动画应用到我的动作中ActionBar.对于ActionBar我使用ActionBarSherlock.
我的问题是,在我找到的所有解决方案中(例如ActionItem的动画图标),他们正在获取MenuItem动画的内容onOptionsItemSelected(MenuItem item).
但是我希望能够在选择某个动作之前启动动画.那我该MenuItem怎么办呢?