/ / TextViewの座標を設定する - android、android-textview

TextViewの座標を設定する - android、android-textview

私は今プロジェクトに取り組んでいます。画面に複数のTextViewがあります。アプリケーションを開いたときにランダムなx座標とy座標を持つようにします。

TextView.x = 30、TextView = 30のようなものはありますか。

回答:

回答№1は1

TextViewを FrameLayout を使って座標を設定する アンドロイド:layout_marginTop そして アンドロイド:layout_marginLeft。 FrameLayoutはそのアイテムを左上隅レイアウト内の項目の順序を変更することでz軸を操作できます。最初の項目は2番目の項目の下にあります。

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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:layout_marginTop="10dp"
android:layout_marginLeft="10dp"/>
<TextView
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginLeft="60dp"/>
</FrameLayout>

コードから動的に設定することもできます。

TextView textView = (TextView) findViewById(R.id.some_textview);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.topMargin = 10; // margin in pixels, not dps
layoutParams.leftMargin = 10; // margin in pixels, not dps
textView.setLayoutParams(layoutParams);

回答№2の場合は0
 TextView textView = (TextView) findViewById(R.id.display);
textView.setLayoutParams(new AbsoluteLayout.LayoutParams(100,40, 100, 70));

しかし、ここで私たちは使用することができます AbsoluteLayoutこれは廃止予定です。