无法在活动中放置任何小部件

时间:2018-09-11 03:28:36

标签: java android android-studio android-activity

我的android studio或代码有问题,但几周前我无法在设计面板中放置任何内容,只能放置按钮。现在有人可以告诉我这是什么问题吗?顺便说一句,我的其他活动除此以外一切正常

这是我的Options.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#D3D3D3">

<Button
    android:layout_width="280dp"
    android:layout_height="wrap_content"
    android:text="Back"
    android:id="@+id/back"
    android:background="@drawable/button_red"
    android:textColor="#ffffff"
    android:textSize="25dp"
    android:onClick="Back"
    android:layout_marginBottom="30dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

这是我的Options.java

public class Options extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.options);

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);

    int width = dm.widthPixels;
    int height = dm.heightPixels;

    getWindow().setLayout((int)(width*.9),(int)(height*.9));

    Typeface myTypeFace = Typeface.createFromAsset(getAssets(), "terminator.TTF");
    Button Back = (Button)findViewById(R.id.back);
    Back.setTypeface(myTypeFace);

}

public void Back (View view) {

    Intent openMainActivity= new Intent(Options.this, Menu.class);
    openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivityIfNeeded(openMainActivity, 0);

}
}

0 个答案:

没有答案