Android Mainactivity不显示activity_main.xml

时间:2015-03-04 20:53:06

标签: java android xml android-imageview

activity_main.xml更改了部分应用设计并启动应用后,MainActivity课程设计不会改变。 在我将工作空间从平板电脑更改为Android手机后,我尝试更改设计,并且设计不适合手机上的图像视图太大而且它们填满了所有手机屏幕的任何建议如何使其适合手机?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_1"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.flagsgame.MainActivity" >

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/start_btn"
        android:layout_width="295dp"
        android:layout_height="wrap_content"
        android:text="@string/start_game" />
</LinearLayout>

<Button
    android:id="@+id/reguler"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/linearLayout1"
    android:layout_alignRight="@+id/linearLayout1"
    android:layout_below="@+id/linearLayout1"
    android:text="Classic Mode"
    android:visibility="invisible" />

<Button
    android:id="@+id/time"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/reguler"
    android:layout_alignRight="@+id/reguler"
    android:layout_below="@+id/reguler"
    android:text="Time Attack Maddness" 
    android:visibility="invisible"/>

public class MainActivity extends Activity implements OnClickListener {

private static final String TAG = "Flagss Game" ;//יצירת טאג למשחק לשימוש בםונקציות כמו exception

Button start;
Button time;
Button reguler;
DatabaseHandler db = new DatabaseHandler(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //List<Flagss> arrAdd= new ArrayList<Flagsss>();

    start = (Button)findViewById(R.id.start_btn);
    time = (Button)findViewById(R.id.time);
    reguler = (Button)findViewById(R.id.reguler);
    start.setOnClickListener(this);
    db = new DatabaseHandler(this);

    creat_rows();
}

/*
//קבלת התמונות
private void pic_view(String pic2) {

    // TODO Auto-generated method stub

    //Log.d("Result from pic function " , pic2);
    ImageView imageView = (ImageView)findViewById(R.id.imageView1);
    String uri ="@drawable/";
    uri += pic2;
    int imageResource = getResources().getIdentifier(uri, null, getPackageName());
    Drawable res= getResources().getDrawable(imageResource);
    imageView.setImageDrawable(res);

}*/

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    start.setVisibility(start.INVISIBLE);
    time.setVisibility(time.VISIBLE);
    reguler.setVisibility(reguler.VISIBLE);

    //Intent s = new Intent(this,ClassicMode.class);
    //startActivity(s);

    reguler.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cm = new Intent(MainActivity.this,ClassicMode.class);
            //Intent c = new Intent(MainActivity.class ,ClassicMode.class);
            startActivity(cm); 
        }
    });

    time.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent tm = new Intent(MainActivity.this,TimeAttack.class);
            startActivity(tm);
            Log.d(TAG, "inside time");
        }
    });
}

1 个答案:

答案 0 :(得分:0)

请确保已将activity_main.xml文件保存在正确的布局目录中。您可能已将其更改为另一种布局。因此,请验证项目中的所有activity_main.xml。