facebook twitter hatena line email

「Android/UIテキスト」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==テキスト書き換え== *xmlレイアウト <<nowiki />TextView android:layout_width="match_parent" android:id="@+id/textView1" android:text="...」)
 
(テキスト書き換え)
(同じ利用者による、間の1版が非表示)
行1: 行1:
 
==テキスト書き換え==
 
==テキスト書き換え==
 
*xmlレイアウト
 
*xmlレイアウト
  <<nowiki />TextView android:layout_width="match_parent"
+
  <<nowiki />TextView android:id="@+id/textView1"
          android:id="@+id/textView1"
+
 
           android:text="@string/hello"
 
           android:text="@string/hello"
           android:layout_height="wrap_content">
+
          android:layout_width="match_parent"
</TextView>
+
           android:layout_height="wrap_content" />
 
*java
 
*java
 
  TextView textView1 = (TextView)findViewById(R.id.textView1);
 
  TextView textView1 = (TextView)findViewById(R.id.textView1);

2019年3月8日 (金) 19:31時点における版

テキスト書き換え

  • xmlレイアウト
<TextView android:id="@+id/textView1"
          android:text="@string/hello"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" />
  • java
TextView textView1 = (TextView)findViewById(R.id.textView1);
textView1.setText("テスト");

テキストアウトライン設定

  • xml
<TextView android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:textColor="#ffffffff"
           android:shadowColor="#ff000000"
           android:shadowDy="0"
           android:shadowDx="0"
           android:shadowRadius="4"
           android:text="test"/>

改行テキスト

  • xml
<TextView android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:text="1、\nテストです\n\n2、てすとです"
           android:singleLine="false"
/>

¥nでなく\nでなければならない。

中央寄せ

android:gravity="center"

フォントサイズ

android:textSize="18sp"

余白

android:paddingTop="10sp"
android:paddingBottom="10sp"
android:paddingLeft="10sp"
android:paddingRight="10sp"

match_parentとmatch_parent

同じ意味だが、match_parentの方が推奨(android 2.2[API 8]以上)

参考: http://android49.blog.fc2.com/blog-entry-20.html