垂直方向と水平方向の中央に異なる数の行が存在する可能性があるn個のテキストビューを整列させようとしています。サイズと中央の配置が固定されている場合でも、より多くの行を持つテキストビューは「落下」します。それらをコードで整列させることは可能ですか?
これは私のxmlです:
<LinearLayout 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" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one line"
android:textSize="48dp"
tools:context=".MainActivity" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two lines"
android:textSize="48dp" />
</LinearLayout>
これは私のJavaクラスです:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView oneline=(TextView) findViewById(R.id.textView1);
TextView twolines=(TextView) findViewById(R.id.textView2);
twolines.setText("two lines \n two lines");
oneline.setHeight(200);
twolines.setHeight(200);
oneline.setWidth(400);
twolines.setWidth(400);
oneline.setBackgroundColor(Color.YELLOW);
twolines.setBackgroundColor(Color.YELLOW);
oneline.setGravity(Gravity.CENTER);
twolines.setGravity(Gravity.CENTER);
}
そしてこれが結果です:-\