質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.51%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

3回答

8824閲覧

Textviewの外枠はそのままに文字の位置だけ変えたい

yojouhan

総合スコア12

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2015/12/28 03:21

編集2015/12/28 03:24

Textviewの外枠はそのままに文字の位置だけ変えたい

Adnroidのlayoutについて質問をさせて頂きます。

ひとつのグループに複数のTextViewを配置した際に、
TextView内の文字のみ位置をずらしたいのですが、
どうしても外枠ごと移動してしまいます。

どなたかこちらの設定についてご教授頂けないでしょうか。

以上、宜しくお願い致します。

■現象
・gravityをtopに設定した際に画像1のようになってしまう
画像1
https://www.dropbox.com/s/wbuvtejlourbh17/tera_pic1.png?dl=0

■期待動作
・gravityをtopに設定した際に画像2のようになる
画像2
https://www.dropbox.com/s/7ybriezl4l9yv9u/tera_pic2.png?dl=0


■問題のlayout(一部抜粋)

xml

1<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 3 android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 4 android:paddingRight="@dimen/activity_horizontal_margin" 5 android:paddingTop="@dimen/activity_vertical_margin" 6 android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity" 7 android:orientation="vertical"> 89 <LinearLayout 10 android:orientation="horizontal" 11 android:layout_width="fill_parent" 12 android:layout_height="wrap_content"> 13 14 <TextView 15 android:layout_width="wrap_content" 16 android:layout_height="wrap_content" 17 android:text="0" 18 android:id="@+id/Num1" 19 android:layout_weight="5.0" 20 android:height="80dp" 21 android:background="@android:drawable/alert_light_frame" 22 android:width="80dp" 23 android:gravity="center|top" /> 24 25 <TextView 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:text="+" 29 android:id="@+id/operand" 30 android:layout_weight="1.0" 31 android:height="50dp" 32 android:width="50dp" 33 android:textStyle="bold" 34 android:textColor="#0000FF" 35 android:gravity="center" /> 36 37 <TextView 38 android:layout_width="wrap_content" 39 android:layout_height="wrap_content" 40 android:text="0" 41 android:id="@+id/Num2" 42 android:layout_weight="5.0" 43 android:height="80dp" 44 android:background="@android:drawable/alert_light_frame" 45 android:width="80dp" 46 android:gravity="center" /> 47 48 <TextView 49 android:layout_width="wrap_content" 50 android:layout_height="wrap_content" 51 android:text="=" 52 android:id="@+id/textView6" 53 android:layout_weight="1.0" 54 android:height="50dp" 55 android:width="50dp" 56 android:textStyle="bold" 57 android:gravity="center" /> 58 59 <TextView 60 android:layout_width="wrap_content" 61 android:layout_height="wrap_content" 62 android:text="0" 63 android:id="@+id/result" 64 android:layout_weight="10" 65 android:height="100dp" 66 android:width="100dp" 67 android:background="@android:drawable/alert_light_frame" 68 android:gravity="center" /> 69 </LinearLayout> 7071```: 72--------------------------------------------------

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答3

0

自己解決

下記のようにtableLayoutとする事で事故解決致しました。
ご回答くださった皆様、本当にありがとうございました。

xml

1 <LinearLayout 2 android:orientation="horizontal" 3 android:layout_width="fill_parent" 4 android:layout_height="wrap_content"> 5 6 <TableLayout 7 android:layout_width="wrap_content" 8 android:layout_height="match_parent"> 9 10 <TableRow 11 android:layout_width="match_parent" 12 android:layout_height="match_parent" 13 android:minHeight="16dp" 14 android:minWidth="80dp"> 15 16 <TextView 17 android:layout_width="fill_parent" 18 android:layout_height="fill_parent" 19 android:id="@+id/Num1_0_0" 20 android:background="#ffffff" 21 android:width="16dp" 22 android:height="16dp" /> 23 24 <TextView 25 android:layout_width="fill_parent" 26 android:layout_height="fill_parent" 27 android:id="@+id/Num1_1_0" 28 android:background="#ffffff" 29 android:width="16dp" 30 android:height="16dp" /> 31 32 <TextView 33 android:layout_width="fill_parent" 34 android:layout_height="fill_parent" 35 android:id="@+id/Num1_2_0" 36 android:background="#ffffff" 37 android:width="16dp" 38 android:height="16dp" /> 39 40 <TextView 41 android:layout_width="fill_parent" 42 android:layout_height="fill_parent" 43 android:id="@+id/Num1_3_0" 44 android:background="#ffffff" 45 android:width="16dp" 46 android:height="16dp" /> 47 48 <TextView 49 android:layout_width="fill_parent" 50 android:layout_height="fill_parent" 51 android:id="@+id/Num1_4_0" 52 android:background="#ffffff" 53 android:width="16dp" 54 android:height="16dp" /> 55 56 </TableRow> 57

投稿2016/01/11 07:55

yojouhan

総合スコア12

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

各textViewにandroid:layout_gravity="center"```XML
android:layout_gravity="center"

投稿2016/01/06 00:42

ayumu

総合スコア86

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yojouhan

2016/01/06 14:50

ご回答ありがとうございます! ご教授頂いた設定も試してみたのですが、 全てにandroid:layout_gravity="center"のみを設定した場合 TextViewのY軸位置は正しく並行になったのですが、 そこからtopを指定すると同様に崩れてしまうようです… やはり一部だけ枠の上付きにしたい場合はtable layoutなどで別途用意するしかないでしょうか…
ayumu

2016/01/06 15:29

こちらで試してみたところ、LinerLayoutでgravity="center" 各textView内でgravity="center|top"と指定したところ正常にできました linerLayout内のviewであるtextViewを中央に配置し、textView内の文字をtextView内で指定しているためこうなると思います
guest

0

少し意味がわからないんですがid@Num1のgravityがtopも混じっているのでtopを取ったら字が真ん中にいくと思います。

投稿2015/12/28 03:43

momiji0319

総合スコア15

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yojouhan

2015/12/29 05:44 編集

ご回答ありがとうございます、 また質問内容が分かりづらく申し訳ありません。 添付の絵にもありますが 枠ごと移動するのを避け、 「枠に上付きで文字が表示される」事が 実現したいです。 同列の他Textviewの枠と同じ水平位置に、表示させたいです。 以上、宜しくお願い致します。
momiji0319

2015/12/30 06:08

であればcenter属性を取り除きcenter_horizontal属性を追加すればいいと思います
yojouhan

2015/12/30 17:56

何度も申し訳ありません。 ただ上記layoutですと、 center属性を取り除き、center_horizontal属性のみにしても 画像1のように枠の位置が崩れてしまいます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.51%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問