Java Android的第二个活动是忽略xml文件

Java Android的第二个活动是忽略xml文件,java,android,xml,android-4.4-kitkat,Java,Android,Xml,Android 4.4 Kitkat,在我的第二个活动中,我有一个textview,它不响应xml文件中的更改,我试图更改文本大小和对齐方式,但我所做的一切都不起作用,我只能猜测这是因为在活动的java文件中,我有一个.setText方法更改textView的文本,这导致程序忽略xml文件,我的问题是现在如何更改文本大小 Java代码: package com.powermedia.rps; import android.os.Bundle; import android.support.v7.app.ActionBarActivi

在我的第二个活动中,我有一个textview,它不响应xml文件中的更改,我试图更改文本大小和对齐方式,但我所做的一切都不起作用,我只能猜测这是因为在活动的java文件中,我有一个.setText方法更改textView的文本,这导致程序忽略xml文件,我的问题是现在如何更改文本大小

Java代码:

package com.powermedia.rps;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* Created by Joshua on 2/17/2015.
*/
public class ResultActivity extends ActionBarActivity implements      View.OnClickListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
    Button playAgainBtn;
    TextView resulttv;
    String userChoice = "";
    String AndroidChoice = "";
    super.onCreate(savedInstanceState);
    setContentView(R.layout.result);
    playAgainBtn = (Button)findViewById(R.id.PlayAgain);
    playAgainBtn.setOnClickListener(this);
    resulttv = (TextView)findViewById(R.id.textView);
    userChoice = this.getIntent().getExtras().getString("userChoice");
    AndroidChoice = this.getIntent().getExtras().getString("AndroidChoice");
    resulttv.setText("User chose " + userChoice + ", Android chose " +   AndroidChoice +
    "\n" + getWinner(AndroidChoice, userChoice) + " won!");
}
XML代码:

<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#ffd3d3d3"
android:id="@+id/test">

<Space
    android:layout_width="fill_parent"
    android:layout_height="24dp"
    android:id="@+id/space3"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true" />

<Button
    android:layout_width="95dp"
    android:layout_height="wrap_content"
    android:text="Play Again"
    android:id="@+id/PlayAgain"
    android:layout_below="@+id/space3"
    android:layout_centerHorizontal="true"
    android:background="#ff959595" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:textSize="20dp"
    android:textStyle="bold"
    android:text="Tell who won or tie"
    android:textAlignment="center" />

更改:

android:textSize="20dp"
致:


没有什么被忽视。加载xml文件后,您可以在Java中更改文本,但不会更改文本大小或其他任何内容。在运行应用程序之前,确保您的
TextView
具有GUI中所需的正确属性。您可能还需要更好地解释,因为问题/问题并不完全清楚。您应该将按钮和文本视图的声明从
onCreate()
移到类的私有成员变量。不确定当
onCreate()
完成并且您(比如)单击Button@DavidM为什么?如果它们没有在其他地方使用,那么这正是它们应该去的地方。@codeMagic-他在按钮上声明了一个onClickListener。按钮在
onCreate()之后超出范围。对我来说似乎是个错误。试着清理你的项目并重建。听起来这些更改没有被编译
android:textSize="20sp"