Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否尝试更改setText()方法的对齐方式?_Java_Android_Css - Fatal编程技术网

Java 是否尝试更改setText()方法的对齐方式?

Java 是否尝试更改setText()方法的对齐方式?,java,android,css,Java,Android,Css,我正在尝试更改Textview的setText方法的对齐方式。要清楚,在我的模拟器上,我正在尝试对齐setText的文本。但是我没有成功。下面是我的代码 <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:textColor="#ff0

我正在尝试更改Textview的setText方法的对齐方式。要清楚,在我的模拟器上,我正在尝试对齐setText的文本。但是我没有成功。下面是我的代码

       <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textColor="#ff00ff"
        android:text="@string/username"
        android:background="#00ff00"
        android:id = "@+id/text1"
        android:textColorHighlight="#000000"
        android:textIsSelectable="true"
        android:textAlignment="center"
        android:layout_alignParentTop="true"/>

任何建议都会很有帮助

因为它不采用重力常数。它有自己的一套。看,你现在做的真的很糟糕

通常,正确的方法是设置textview的布局,或者根据字符串的大小和您试图获得的效果,按照您想要的方式对齐textview本身

       TextView t1,t2;
       t1 = (TextView)(findViewById(R.id.text1));
       System.out.println(t1.toString());
       tableRow = new TableRow(getApplicationContext());
       t1 =new TextView(getApplicationContext());
       t1.setText("Username");
       t1.setTextSize(20);
       t1.setTextAlignment(Gravity.BOTTOM); //This is what I'm trying!!
       t1.setTextColor(Color.RED);
       t1.setTypeface(null, Typeface.BOLD);
       t1.setPadding(15, 35, 15, 15);
       t1.setAllCaps(true);
       t1.setBackgroundResource(R.drawable.cellgrey);
       tableRow.addView(t1);