0
我有這個非常簡單的代碼循環, 我沒有做任何複雜的事情! 的TextAnimation()方法得到調用,但是,它裏面的動畫沒有開始(我看不到任何日誌)動畫無法在SurfaceView中工作
這是我的鱈魚:
我的主要活動:
public class Main extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
我的佈局主:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lineralayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<gamedevelopment.mahdi.nazari.killthemall_training.GameView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<LinearLayout
android:id="@+id/Li_ly"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical">
<TextView
android:id="@+id/level_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:background="#fff"
android:gravity="center"
android:text="fdfdsf"
android:textColor="#000"
android:textSize="60dp" />
</LinearLayout>
我GameView:
public class GameView extends SurfaceView {
TextView level_text;
LinearLayout ly;
public GameView(Context context, AttributeSet attrs) {
super(context, attrs);
start();
}
public GameView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
start();
}
public void start() {
surfaceHolder = getHolder();
surfaceHolder.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.main, null);
level_text = (TextView) v.findViewById(R.id.level_text);
ly = (LinearLayout) v.findViewById(R.id.Li_ly);
TextAnimation();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
firstCreacation = false;
gameLoopThread.setRunning(false);
}
});
}
public void TextAnimation() {
Animation animation = AnimationUtils.loadAnimation(context, R.text_anim);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Log.e("start","");
}
@Override
public void onAnimationEnd(Animation animation) {
ShowLevelText2();
Log.e("End","");
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
level_text.startAnimation(animation);
}
}
任何人都可以幫助我嗎?這段代碼有什麼問題? 謝謝:)
謝謝您的回答,是的,我發現我的問題yesterday.As你說,我膨脹並獲得意見另一個參考,不屏幕上顯示的是真實的。 – MehDi
@MehDi所以如果我是對的,那麼將答案標記爲接受,這樣對其他人可能會有所幫助。 –
但是,如何通過充氣視圖獲得相同的參考?我們誇大viw在代碼上做些事情!有什麼辦法通過膨脹來獲得相同的引用,而不是在Activity中初始化它並通過setter傳遞引用? – MehDi