【问题标题】:rotate text on the button旋转按钮上的文字
【发布时间】:2011-08-24 08:46:30
【问题描述】:

我有以下屏幕:

我正在尝试旋转文本,然后在此按钮上设置文本。

为此,我有以下布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
>
<SurfaceView android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:id="@+id/surface_camera" />


<FrameLayout 
android:layout_width="60dip"
android:layout_height="fill_parent"
>
  <Button           android:layout_width="60dip"
                     android:id="@+id/btnPhoto"
                    android:layout_height="fill_parent"/>

 <TextView 
                    android:layout_width="60dip"
                     android:id="@+id/textview"
                     android:textColor="#000000"
                    android:layout_height="fill_parent"
                  />

</FrameLayout>
 </RelativeLayout>

然后我尝试使用动画来旋转我的文本:

文件:res/anim/myanim:

<?xml version="1.0" encoding="utf-8"?>
<rotate  xmlns:android="http://schemas.android.com/apk/res/android"
       android:fromDegrees="0" 
       android:toDegrees="-90"
       android:pivotX="50%"
       android:pivotY="50%"
       android:duration="0" />

然后我在onCreate()

te = (TextView) findViewById(R.id.textview);
      te.setText(t);

     RotateAnimation ranim = (RotateAnimation)AnimationUtils.loadAnimation(this, R.anim.myanim);
     ranim.setFillAfter(true);
    te.setAnimation(ranim);

但不幸的是,我的按钮上没有出现任何文字。任何人有什么想法吗?

【问题讨论】:

  • 什么 abt te.setVisibility(true);
  • 不工作是什么意思?你想让我为你写整个代码还是什么?我说使用以下代码 te.setVisibility(true);首先你试着提高你的英语来理解 cmets。
  • 我说我在那一行出错了。我的英语没有问题!!!!
  • 你也可以查看这个链接barebonescoder.com/tag/android-animation

标签: android button android-framelayout


【解决方案1】:

创建一个名为 anim 的文件夹,然后创建 xml 文件并将其添加到 xml 下方

<rotate 
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0" 
android:toDegrees="360" 
android:pivotX="50%"
android:pivotY="50%"
 android:repeatCount="infinite" 
 android:duration="1200" />

然后在您定义 textView 的 xml 中的 textview 上添加以下行。

android:interpolator="@anim/linear_interpolator" 

最后应用下面的代码...

Animation logoMoveAnimation = AnimationUtils.loadAnimation(Animation2DActivity.this,
                    R.anim.linear_interpolator);
            mobjectImageButton.startAnimation(logoMoveAnimation);

享受吧。

【讨论】:

    猜你喜欢
    • 2021-10-08
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多