- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在画廊中使用了 FrameLayout 作为画廊项目。 FrameLayout 中有 2 个 RelativeLayouts,每个都有一些 TextView 和一个 ImageView。图库外有一个名为“翻转”的按钮。单击“翻转”按钮会隐藏一个相关布局并显示另一个带有翻转动画的布局。 Gallery 外还有一个 TextView,我在其中更新了一些文本。当用户滚动 Gallery 以选择另一个项目时,我会从 Gallery 的 setOnItemSelected 方法更新 TextView。
问题是如果我不通过 setOnItemSelected 方法更新 TextView,翻转动画将正常工作。但是,如果我更新 TextView,则动画将不起作用。即使它不切换 FrameLayout 内的 RelativeLayout。
如果有人知道问题出在哪里,请帮助我。
这是主屏幕的 XML 布局:
<?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>
这里是画廊项目的 XML 布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_margin="0dip" android:padding="0dip">
<RelativeLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/wordDetailsRelativeLayout" android:background="#FFFF">
<TextView android:gravity="center" android:textSize="18sp" android:layout_alignParentTop="true" android:layout_width="fill_parent" android:text="Apathy" android:textStyle="bold" android:layout_height="wrap_content" android:layout_marginBottom="5dip" android:layout_marginTop="5dip" android:id="@+id/wordTextView" android:textColor="#FF1a3f6e"></TextView>
<TextView android:gravity="center" android:layout_width="fill_parent" android:text="verb" android:layout_height="wrap_content" android:id="@+id/partsOfSpeechTextView" android:layout_below="@+id/wordTextView" android:layout_marginBottom="5dip"></TextView>
<LinearLayout android:paddingBottom="5dip" android:layout_width="fill_parent" android:gravity="center" android:background="#FFFF" android:id="@+id/LinearLayout01" android:layout_height="wrap_content" android:layout_alignParentBottom="true"><ImageView android:src="@drawable/iphone_vocabulary_logo_15" android:id="@+id/logoImageView" android:layout_height="wrap_content" android:layout_width="wrap_content"></ImageView>
</LinearLayout>
<LinearLayout android:layout_height="fill_parent" android:layout_marginBottom="5dip" android:layout_width="fill_parent" android:layout_below="@+id/partsOfSpeechTextView" android:orientation="vertical" android:id="@+id/imageAndMeaningLinearLayout" android:gravity="top|center_horizontal" android:layout_above="@+id/LinearLayout01"><ImageView android:id="@+id/wordImageView" android:layout_height="wrap_content" android:layout_width="wrap_content"></ImageView>
<TextView android:layout_height="wrap_content" android:id="@+id/wordMeaningTextView" android:layout_width="wrap_content" android:textColor="#F000" android:textSize="15sp" android:layout_marginLeft="10dip" android:layout_marginTop="10dip" android:layout_marginRight="10dip" android:gravity="center"></TextView>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:background="#FFFF" android:id="@+id/wordScriptRelativeLayout" android:visibility="gone">
<TextView android:gravity="center" android:textSize="18sp" android:layout_alignParentTop="true" android:layout_width="fill_parent" android:text="Apathy" android:textStyle="bold" android:layout_height="wrap_content" android:layout_marginBottom="5dip" android:layout_marginTop="5dip" android:textColor="#FF1a3f6e" android:id="@+id/wordTextView2"></TextView>
<TextView android:gravity="center" android:layout_width="fill_parent" android:text="verb" android:layout_height="wrap_content" android:id="@+id/partsOfSpeechTextView2" android:layout_below="@+id/wordTextView2" android:layout_marginBottom="5dip"></TextView>
<LinearLayout android:paddingBottom="5dip" android:layout_width="fill_parent" android:gravity="center" android:background="#FFFF" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:id="@+id/LinearLayout02"><ImageView android:src="@drawable/iphone_vocabulary_logo_15" android:id="@+id/logoImageView" android:layout_height="wrap_content" android:layout_width="wrap_content"></ImageView>
</LinearLayout>
<LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/wordScriptLinearLayout" android:gravity="top|center_horizontal" android:layout_below="@+id/partsOfSpeechTextView2" android:layout_above="@+id/LinearLayout02"><TextView android:layout_height="wrap_content" android:layout_margin="10dip" android:id="@+id/wordScriptTextView" android:layout_width="fill_parent" android:textColor="#F000" android:textSize="15sp"></TextView>
</LinearLayout>
</RelativeLayout>
</FrameLayout>
在主屏幕中,当用户单击 showScriptButton(页脚的右侧按钮)时,framelayout 的一个相对布局将与另一个相对布局切换。相对布局的切换以翻转动画显示。
现在,页脚中间有一个 TextView 。如果我们从代码中更改该 TextView 的文本,那么即使框架布局未更改相关布局,翻转动画也不起作用。
这是图库的 setOnItemSelectedListener 方法:
wordsGallery.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long arg3) {
durationTextView.setText("");
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
这是播放按钮的方法:
private void playAudio() {
if(isPaused) {
myRefreshThread = new Thread(new secondCountDownRunner());
myRefreshThread.start();
audioPlayer.start();
} else {
audioPlayer = MediaPlayer.create(this, ApplicationCache.wordAudioList.get(word.wordText));
audioPlayer.setOnCompletionListener(this);
int totalDuration = audioPlayer.getDuration()/1000;
String durationText = "";
int min = totalDuration/60;
int seconds = totalDuration % 60;
if(min < 10)
durationText = "0";
durationText += min+":";
if(seconds < 10)
durationText += "0";
durationText += seconds;
System.out.println("Duration of audio:"+durationText);
durationTextView.setText(durationText);
myRefreshThread = new Thread(new secondCountDownRunner());
myRefreshThread.start();
audioPlayer.start();
}
isPaused = false;
isPlaying = true;
playButton.setBackgroundResource(R.drawable.pause_button);
}
这是第二个 CountDownRunner 线程:
class secondCountDownRunner implements Runnable{
// @Override
public void run() {
while(!Thread.currentThread().isInterrupted()){
Message m = new Message();
m.what = 2;
audioPlayerHandler.sendMessage(m);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
这里是 audioPlayerHandler:
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);
}
}
}
};
这是单击 showScriptButton 时调用的方法:
public void flipView(int position) {
applyRotation(0, 90, position);
isFrontShowing[position] = !isFrontShowing[position];
}
private void applyRotation(float start, float end, int position) {
// Find the center of image
final float centerX, centerY;
if(isFrontShowing[position] == true) {
centerX = detailsLayout[position].getMeasuredWidth() / 2.0f;
centerY = detailsLayout[position].getMeasuredHeight() / 2.0f;
} else {
centerX = scriptLayout[position].getMeasuredWidth() / 2.0f;
centerY = scriptLayout[position].getMeasuredHeight() / 2.0f;
}
//System.out.println("center X:"+centerX+",Y:"+centerY);
// Create a new 3D rotation with the supplied parameter
// The animation listener is used to trigger the next animation
final Flip3dAnimation rotation =
new Flip3dAnimation(start, end, centerX, centerY);
rotation.setDuration(500);
rotation.setFillAfter(true);
rotation.setInterpolator(new AccelerateInterpolator());
rotation.setAnimationListener(new DisplayNextView(isFrontShowing[position], detailsLayout[position], scriptLayout[position]));
if (isFrontShowing[position] == true)
{
//detailsLayout[position].requestFocus();
//detailsLayout[position].bringToFront();
detailsLayout[position].startAnimation(rotation);
} else {
//System.out.println("---Backward flipping started...");
//scriptLayout[position].requestFocus();
//scriptLayout[position].bringToFront();
scriptLayout[position].startAnimation(rotation);
}
}
这是 Flip3dAnimation 类:
import android.graphics.Camera;
导入android.graphics.Matrix;导入 android.view.animation.Animation;导入 android.view.animation.Transformation;
公共(public)类 Flip3dAnimation 扩展动画 { 私有(private)最终 float mFromDegrees; 私有(private)最终 float mToDegrees; 私有(private)最终 float mCenterX; 私有(private)最终 float mCenterY; 私有(private)相机 mCamera;
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;
公共(public)最终类 DisplayNextView 实现 Animation.AnimationListener { 私有(private) bool mCurrentView; RelativeLayout布局1; RelativeLayout布局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) {
}
交换 View 类:
import android.view.View;
导入android.view.animation.Animation;导入 android.view.animation.DecelerateInterpolator;导入 android.view.animation.Animation.AnimationListener;导入 android.widget.RelativeLayout;
公共(public)最终类 SwapViews 实现 Runnable { 私有(private) bool mIsFirstView; RelativeLayout布局1; RelativeLayout布局2;
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 作为顶级 LinearLayout 的唯一子级?我认为您布局的复杂性可能与此问题有关,因此我在这里提供了一个更简单的替代方案,它使用 android:layout_weight
使图库填充页眉或页脚未使用的空间。如果这有帮助,请告诉我。
<?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>
关于android - 在 framelayout 之外的 TextView 中更改文本时,FrameLayout 动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4992950/
我正在尝试使用 RelativeLayout 扩充 FrameLayout。然后我像这样扩展一个 FrameLayout: public class Keyboard extends FrameLay
在我的应用程序中,我有一个布局,它有一个 RelativeLayout 我想在运行时以编程方式设置边距。但是当我这样做时,它给了我 ClassCastException 说 FrameLayout 不
我在横向模式下的 FrameLayout 中打开 android Camera,然后屏幕看起来像- 但是当我在 FrameLayout 中的 ImageView 中打开相同的图像时,它看起来像 - 请
我在画廊中使用了 FrameLayout 作为画廊项目。 FrameLayout 中有 2 个 RelativeLayouts,每个都有一些 TextView 和一个 ImageView。图库外有一个
我目前正在使用 xml 为 Activity 创建布局,内容 (FrameLayout) 应该填满整个屏幕。不幸的是,事实并非如此。只有当我将边距更改为以下时,它才有效: 左:-17dp 右:-19d
我有一个 View (假设它是 MyFramLayout)扩展了 FrameLayout,我无法在按下键时让这个 FrameLayout 获得焦点(我在电视平台上工作)。 布局是这样的:
我正在尝试设置一个平板电脑布局,左侧是一个列表,右侧是一个详细信息 Pane 。单击列表项时,详细信息 Pane 将填充一系列比左侧列表更长的卡片。我希望详细信息 Pane 和列表(回收站 View
我用按钮创建了一个布局,这个按钮有逻辑,我不想集成它。 所以我认为: 当我有按钮时,我需要添加一个 char $,所以我创建了一个 frameLayout 并在此处添加了一个 TextView,我这样
我正在使用 FrameLayouts 在图像上重叠图像,但在这种特殊情况下我无法理解我的内部 FrameLayout 没有显示在另一幅图像的前面。这是理论: 这是实际的事情: 这是我的 XML:
在 FrameLayout 中,我动态添加了一个 WebView,用于在旋转屏幕时保存内容,但事实并非如此,情况是在 FrameLayout 下面我想放置一个固定的页脚。下一个代码放置页脚,但 Fra
我在加载 fragment Activity 时意外收到空指针异常错误。我指的是 FrameLayout 将用户定向到另一个 Activity (在单击按钮时)。 11-10 07:31:58.773
我想测试使用 fragment 管理器动态替换 fragment 。在主布局中,在父衬里布局下,我有 3 个布局,一个子线性布局和 2 个子框架布局。这个想法是在第一个子线性布局中使用一个按钮来交换第
我正在开发 Android 即时聊天应用程序。在聊天 Activity 中,我正在使用 FrameLayout。以下是 xml 文件: 我已将框架的可见性设置为
这是有效的: a) main.xml 中带有两个 ImageView 的 FrameLayout b) 在背景上旋转动画,而前景部分保持不变 因为我需要对背景图像做更多的工作,
我有以下问题:我有很长的 ListView,但是当我向上滚动时会触发 onRefresh,而不是先滚动回顶部。我该如何解决这个问题? 我将以下 fragment 插入到 FrameLay
我有一个 FrameLayout,上面显示了一个 LinearLayout我的 Intent 是这个 LinearLayout 总是占据屏幕的 33%……但我做不到。我尝试使用“dp”,但当然,结果因
是否有一种布局,其中的项目可以像 Android 的 FrameLayout 一样分层放置? 我已经在谷歌上搜索了一段时间,但找不到类似的东西。 最佳答案 我希望这个答案很清楚并且可以帮助您。您需要的
我是第一次使用 NavigationBar 小部件,我无法将 FrameLayout 设置为不在 NavigationBar 后面。我已经尝试了一切:在 RelativeLayout 中设置(Navi
我有以下 View 层次结构: 我尝试设置 ImageView 的下边距,在布局编辑器上它似乎工作正常,但是当我运行代码时,我设置的下边距被丢弃了。
我有这样的布局: 相对布局 框架布局 fragment (谷歌地图图层) 复选框 ...其他按钮和东西 现在我想在选中 Checkbox 时捕获 FrameLayout 上的触摸事件。我用 dispa
我是一名优秀的程序员,十分优秀!