我想改变一个组件的某些属性,比如旋转。
我这样试试:
package com.dev.moritz.colora;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class gameActivity extends AppCompatActivity{
public ImageView square;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
square = (ImageView) findViewById(R.id.game_square);
setContentView(R.layout.activity_game);
square.setRotation(square.getRotation() + 90);
}
public void layout_click(View v) {
}
}
但是当我开始这个应用程序崩溃时。没有旋转一切都有效,所以存在问题。 我该怎么办?
Moritz的
答案 0 :(得分:0)
尝试在视图
之前绑定setContentView()
setContentView(R.layout.activity_game);
square = (ImageView) findViewById(R.id.game_square);
square.setRotation(square.getRotation() + 90);
<强>代替强>
square = (ImageView) findViewById(R.id.game_square);
setContentView(R.layout.activity_game);
square.setRotation(square.getRotation() + 90);