Android layout drawing glitch

不打扰是莪最后的温柔 提交于 2019-12-08 10:39:51

问题


I am writing an android game, I have created a layout for the main menu which has this XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvStats"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="fill_horizontal"
        android:gravity="fill_horizontal" >

        <Button
            android:id="@+id/btnStartSurvive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:gravity="center_vertical|center_horizontal"
            android:text="Start Survival Mode" />

        <Button
            android:id="@+id/btnStartChall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:text="Start Callenge Mode" />

    </LinearLayout>

</LinearLayout>

The layout is shown on the screen using this activity:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.*;

public class MainActivity extends Activity {


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

        //Get rid of the stuff around the edges
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        //show layout
        setContentView(R.layout.main_menu);
        Button btnStart = (Button)findViewById(R.id.btnStartSurvive);
        btnStart.setOnClickListener(oclStart);
    }

    private OnClickListener oclStart = new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(MainActivity.this, GameActivity.class);
            intent.putExtra("gametype", 'S');
            startActivity(intent);  
        }
    };

}

When I run this on my phone (Android 4.2.2) I get something that looks like this:

Clicking the unused button makes it look like this:

When I run this on my older tablet (Android 2.2) I get what I expected:

Is this an Android Bug? How do I get around it?

Or is it my fault? How do I fix it?


回答1:


I've managed to duplicate the same results, on a Galaxy s4, running 4.2.2. Buttons don't seem to work all that well for some reason.

Have you tried changing the theme? Sometimes the theme will mess up a layout.



来源:https://stackoverflow.com/questions/15599616/android-layout-drawing-glitch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!