Android 在FrameLayout外部的textview中更改文本时,FrameLayout动画不起作用
我已将库中的FrameLayout用作库项。FrameLayout中有两个RelativeLayout,每个都包含一些TextView和一个ImageView。画廊外有一个叫做“翻转”的按钮。单击按钮“翻转”隐藏一个相对布局,并显示另一个具有翻转动画的布局。画廊外还有一个文本视图,我在其中更新了一些文本。当用户滚动Gallery以选择其他项目时,我会从Gallery的setOnItemSelected方法更新TextView 问题是,如果我不使用setOnItemSelected方法更新TextView,翻转动画将正常工作。但是,如果我更新了TextView,那么动画就不起作用了。甚至它也不会在FrameLayout内切换RelativeLayout 如果有人知道问题出在哪里,请帮助我 以下是主屏幕的XML布局:Android 在FrameLayout外部的textview中更改文本时,FrameLayout动画不起作用,android,android-widget,Android,Android Widget,我已将库中的FrameLayout用作库项。FrameLayout中有两个RelativeLayout,每个都包含一些TextView和一个ImageView。画廊外有一个叫做“翻转”的按钮。单击按钮“翻转”隐藏一个相对布局,并显示另一个具有翻转动画的布局。画廊外还有一个文本视图,我在其中更新了一些文本。当用户滚动Gallery以选择其他项目时,我会从Gallery的setOnItemSelected方法更新TextView 问题是,如果我不使用setOnItemSelected方法更新Text
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top|center" android:background="#0000">
<RelativeLayout android:id="@+id/RelativeLayout04" android:layout_height="fill_parent" android:layout_width="fill_parent"><RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/top_bar" android:layout_alignParentTop="true" android:id="@+id/headerRelativeLayout"><Button android:id="@+id/homeButton" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:background="@drawable/home_button_open" android:layout_marginLeft="5dip" android:layout_width="wrap_content" android:layout_alignParentLeft="true"></Button>
<Button android:id="@+id/backButton" android:layout_height="wrap_content" android:layout_marginTop="5dip" android:background="@drawable/back_button" android:layout_toRightOf="@+id/homeButton" android:layout_width="wrap_content"></Button>
<TextView android:layout_height="wrap_content" android:textSize="22sp" android:layout_toLeftOf="@+id/LinearLayout02" android:gravity="center" android:layout_toRightOf="@+id/backButton" android:id="@+id/TextView02" android:layout_width="fill_parent" android:textStyle="bold" android:layout_centerInParent="true"></TextView>
<LinearLayout android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_centerVertical="true" android:layout_marginRight="10dip" android:id="@+id/LinearLayout02">
<com.vocabAhead.SATVocab.LoginButton android:layout_marginRight="5dip" android:id="@+id/facebookButton" android:layout_width="wrap_content" android:background="@drawable/facebook_button" android:layout_height="wrap_content"></com.vocabAhead.SATVocab.LoginButton>
<Button android:id="@+id/settingsButton" android:layout_width="wrap_content" android:background="@drawable/settings_button" android:layout_height="wrap_content" android:layout_gravity="center_vertical"></Button>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="35dip" android:background="#FF212121" android:layout_alignParentBottom="true" android:id="@+id/footerRelativeLayout">
<Button android:id="@+id/playButton" android:layout_height="wrap_content" android:background="@drawable/play_button" android:layout_marginLeft="10dip" android:layout_width="wrap_content" android:layout_centerVertical="true" android:layout_alignParentLeft="true"></Button>
<Button android:layout_alignParentRight="true" android:id="@+id/showScriptButton" android:layout_height="wrap_content" android:background="@drawable/infobutton" android:layout_marginRight="10dip" android:layout_width="wrap_content" android:layout_centerVertical="true"></Button>
<TextView android:layout_height="wrap_content" android:textColor="#FFFF" android:id="@+id/itemSerialTextView" android:layout_width="wrap_content" android:layout_centerInParent="true"></TextView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="5dip" android:layout_toRightOf="@+id/playButton" android:id="@+id/durationTextView" android:textColor="#FFFF"></TextView>
</RelativeLayout>
<Gallery android:id="@+id/wordsGallery" android:layout_above="@+id/footerRelativeLayout" android:layout_below="@+id/headerRelativeLayout" android:layout_height="fill_parent" android:layout_width="fill_parent" android:scrollbars="none" android:scrollbarSize="0dip" android:layout_margin="0dip" android:gravity="fill" android:padding="0dip" android:background="#0000"></Gallery>
</RelativeLayout>
</LinearLayout>
这是音频播放器手柄:
audioPlayerHandler = new Handler() {
@Override
public void handleMessage( Message msg )
{
if(msg.what == 1) {
if(isPlaying) {
if(wordsGallery.getSelectedItemPosition() < (ApplicationCache.dontKnowWords.size() - 1)) {
//currentPosition++;
//currentGalleryPosition++;
//isWordScriptShowing = false;
//updateWordDetails();
word = wordsList.get(wordsGallery.getSelectedItemPosition() + 1);
wordsGallery.setSelection(wordsGallery.getSelectedItemPosition() + 1, true);
playAudio();
}
}
} else if(msg.what == 2) {
if(isPlaying) {
int duration = audioPlayer.getDuration()/1000;
int currentPosition = audioPlayer.getCurrentPosition()/1000;
int timeLeft = duration - currentPosition;
if(timeLeft < 0)
timeLeft = 0;
String durationText = "";
int min = timeLeft/60;
int seconds = timeLeft % 60;
if(min < 10)
durationText = "0";
durationText += min+":";
if(seconds < 10)
durationText += "0";
durationText += seconds;
durationTextView.setText(durationText);
}
}
}
};
以下是Flip3dAnimation类:
import android.graphics.Camera;
导入android.graphics.Matrix;
导入android.view.animation.animation;
导入android.view.animation.Transformation
公共类Flip3dAnimation扩展了动画{
私人最终学位;
私人最终浮动协议;
私人最终浮动mCenterX;
私人最终浮动麦肯锡;
私人摄像机麦卡梅拉
public Flip3dAnimation(float fromDegrees, float toDegrees, float centerX,
float centerY) {
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final float fromDegrees = mFromDegrees;
float degrees = fromDegrees
+ ((mToDegrees - fromDegrees) * interpolatedTime);
final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save();
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
DisplayNextView类:
import android.view.animation.Animation;
导入android.widget.RelativeLayout
公共最终类DisplayNextView实现Animation.AnimationListener{
私有布尔mCurrentView;
相对布局1;
相对布局2
public DisplayNextView(boolean currentView, RelativeLayout layout1,
RelativeLayout layout2) {
mCurrentView = currentView;
this.layout1 = layout1;
this.layout2 = layout2;
}
public void onAnimationStart(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
layout1.post(new SwapViews(mCurrentView, layout1, layout2));
}
public void onAnimationRepeat(Animation animation) {
}
public SwapViews(boolean isFirstView, RelativeLayout layout1, RelativeLayout layout2) {
mIsFirstView = isFirstView;
this.layout1 = layout1;
this.layout2 = layout2;
}
public void run() {
final float centerX, centerY;
if(mIsFirstView) {
centerX = layout1.getWidth() / 2.0f;
centerY = layout1.getHeight() / 2.0f;
} else {
centerX = layout2.getWidth() / 2.0f;
centerY = layout2.getHeight() / 2.0f;
}
Flip3dAnimation rotation;
if (mIsFirstView == true) {
layout1.setVisibility(View.GONE);
layout2.setVisibility(View.VISIBLE);
layout2.requestFocus();
layout2.bringToFront();
rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
} else {
layout2.setVisibility(View.GONE);
layout1.setVisibility(View.VISIBLE);
layout1.requestFocus();
layout1.bringToFront();
rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
}
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
rotation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
WordDetailItemAdapter.notifyAdapter();
}
});
if (mIsFirstView == true) {
layout2.startAnimation(rotation);
} else {
layout1.startAnimation(rotation);
}
}
}
SwapView类:
import android.view.View;
导入android.view.animation.animation;
导入android.view.animation.decreater插值器;
导入android.view.animation.animation.AnimationListener;
导入android.widget.RelativeLayout
公共最终类SwapViews实现了Runnable{
私有布尔错误优先视图;
相对布局1;
相对布局2
public DisplayNextView(boolean currentView, RelativeLayout layout1,
RelativeLayout layout2) {
mCurrentView = currentView;
this.layout1 = layout1;
this.layout2 = layout2;
}
public void onAnimationStart(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
layout1.post(new SwapViews(mCurrentView, layout1, layout2));
}
public void onAnimationRepeat(Animation animation) {
}
public SwapViews(boolean isFirstView, RelativeLayout layout1, RelativeLayout layout2) {
mIsFirstView = isFirstView;
this.layout1 = layout1;
this.layout2 = layout2;
}
public void run() {
final float centerX, centerY;
if(mIsFirstView) {
centerX = layout1.getWidth() / 2.0f;
centerY = layout1.getHeight() / 2.0f;
} else {
centerX = layout2.getWidth() / 2.0f;
centerY = layout2.getHeight() / 2.0f;
}
Flip3dAnimation rotation;
if (mIsFirstView == true) {
layout1.setVisibility(View.GONE);
layout2.setVisibility(View.VISIBLE);
layout2.requestFocus();
layout2.bringToFront();
rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
} else {
layout2.setVisibility(View.GONE);
layout1.setVisibility(View.VISIBLE);
layout1.requestFocus();
layout1.bringToFront();
rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
}
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
rotation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
WordDetailItemAdapter.notifyAdapter();
}
});
if (mIsFirstView == true) {
layout2.startAnimation(rotation);
} else {
layout1.startAnimation(rotation);
}
}
}
有人知道这个问题吗。请帮助。在您的主布局中,为什么您将RelativeLayout04作为顶级线性布局的唯一子级?我认为你的布局的复杂性可能与这个问题有关,所以我在这里提供了一个更简单的选择,它使用android:布局权重,使图库填充页眉或页脚未使用的空间。让我知道这是否有帮助
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000"
>
<!-- Header -->
<RelativeLayout
android:id="@+id/headerRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
...
</RelativeLayout>
<!-- The gallery -->
<Gallery
android:id="@+id/wordsGallery"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
...
/>
<!-- Footer -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="35dip"
android:background="#FF212121"
android:layout_alignParentBottom="true"
>
...
</RelativeLayout>
</LinearLayout>
在主布局中,为什么要将RelativeLayout04作为顶级线性布局的唯一子级?我认为你的布局的复杂性可能与这个问题有关,所以我在这里提供了一个更简单的选择,它使用android:布局权重,使图库填充页眉或页脚未使用的空间。让我知道这是否有帮助
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000"
>
<!-- Header -->
<RelativeLayout
android:id="@+id/headerRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
...
</RelativeLayout>
<!-- The gallery -->
<Gallery
android:id="@+id/wordsGallery"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
...
/>
<!-- Footer -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="35dip"
android:background="#FF212121"
android:layout_alignParentBottom="true"
>
...
</RelativeLayout>
</LinearLayout>
你能粘贴一些布局XML和一些代码吗?看到一些Java真的很有帮助,尤其是这个setOnItemSelected方法。你能粘贴一些布局XML和一些代码吗?看到一些Java真的很有帮助,尤其是这个setOnItemSelected方法。当我单击play按钮时,页脚会出现在图库的顶部。除非您在Java代码中操纵布局,否则这是不可能的。显然,您的代码中包含的内容远比您目前发布的内容多得多。请发布您的完整播放按钮点击处理程序。@Reuben:我已经为播放按钮点击处理程序添加了代码。感谢您的帮助。当您单击“播放”按钮时,我看到您通过playButton.setBackgroundResourceR.drawable.pause_button;更改按钮背景;。您确定您的暂停按钮图形大小合适吗?因为是换行内容,所以更改背景可以解释为什么按play键后布局会跳转。尝试将此按钮设置为固定大小,例如48dpx48dp,看看是否有帮助。其次,这与您当前的问题无关,但您不需要专用线程来完成计数秒之类的简单操作。请查看SDK文档中的Handler.postDelayed。更多信息,当我单击“播放”按钮时,页脚会出现在库的顶部。除非您在Java代码中操作布局,否则这是不可能的。显然,您的代码中包含的内容远比您目前发布的内容多得多。请发布您的完整播放按钮点击处理程序。@Reuben:我已经为播放按钮点击处理程序添加了代码。感谢您的帮助。当您单击“播放”按钮时,我看到您通过playButton.setBackgroundResourceR.drawable.pause_button;更改按钮背景;。您确定您的暂停按钮图形大小合适吗?因为是换行内容,所以更改背景可以解释为什么按play键后布局会跳转。尝试将此按钮设置为固定大小,例如48dpx48dp,看看是否有帮助。其次,这与您当前的问题无关,但您不需要专用线程来完成计数秒之类的简单操作。在SDK文档中签出Handler.postdayed。
public SwapViews(boolean isFirstView, RelativeLayout layout1, RelativeLayout layout2) {
mIsFirstView = isFirstView;
this.layout1 = layout1;
this.layout2 = layout2;
}
public void run() {
final float centerX, centerY;
if(mIsFirstView) {
centerX = layout1.getWidth() / 2.0f;
centerY = layout1.getHeight() / 2.0f;
} else {
centerX = layout2.getWidth() / 2.0f;
centerY = layout2.getHeight() / 2.0f;
}
Flip3dAnimation rotation;
if (mIsFirstView == true) {
layout1.setVisibility(View.GONE);
layout2.setVisibility(View.VISIBLE);
layout2.requestFocus();
layout2.bringToFront();
rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
} else {
layout2.setVisibility(View.GONE);
layout1.setVisibility(View.VISIBLE);
layout1.requestFocus();
layout1.bringToFront();
rotation = new Flip3dAnimation(-90, 0, centerX, centerY);
}
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new DecelerateInterpolator());
rotation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
WordDetailItemAdapter.notifyAdapter();
}
});
if (mIsFirstView == true) {
layout2.startAnimation(rotation);
} else {
layout1.startAnimation(rotation);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000"
>
<!-- Header -->
<RelativeLayout
android:id="@+id/headerRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
...
</RelativeLayout>
<!-- The gallery -->
<Gallery
android:id="@+id/wordsGallery"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
...
/>
<!-- Footer -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="35dip"
android:background="#FF212121"
android:layout_alignParentBottom="true"
>
...
</RelativeLayout>
</LinearLayout>