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

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

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

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

Android Studio

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

Q&A

解決済

1回答

1778閲覧

Androidアプリの画面作成について

yojouhan

総合スコア12

Android

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

Android Studio

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

0グッド

0クリップ

投稿2015/06/01 16:37

初めまして、yojouhanと申します。

現在Androidにて電卓アプリを作っているのですが、
並べたボタンが画面をはみ出してしまい、
どのように画面内に納めたらよいか困っております。
(一括指定する方法は無く、ボタン毎にpx数を指定するしか無いのでしょうか?)

またAndroidアプリの画面設計をする際の定石等ありましたら
ご教授頂けたらと思います。

lang

1<RelativeLayout 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 8 <GridLayout 9 android:layout_width="fill_parent" 10 android:layout_height="fill_parent" 11 android:columnCount="11" 12 android:rowCount="13" 13 android:background="@android:color/black" 14 android:id="@+id/gridLayout"> 15 16 <TextView 17 android:layout_width="fill_parent" 18 android:layout_height="wrap_content" 19 android:text="press any key" 20 android:id="@+id/resultText" 21 android:layout_row="1" 22 android:layout_column="1" 23 android:background="@android:color/white" 24 android:password="false" 25 android:phoneNumber="false" 26 android:singleLine="false" 27 android:layout_columnSpan="10" /> 28 29 <Button 30 android:layout_width="wrap_content" 31 android:layout_height="wrap_content" 32 android:text="C" 33 android:id="@+id/clearButton" 34 android:layout_row="2" 35 android:layout_column="1" /> 36 37 <Button 38 android:layout_width="wrap_content" 39 android:layout_height="wrap_content" 40 android:text="÷" 41 android:id="@+id/divisionButton" 42 android:layout_row="2" 43 android:layout_column="3" /> 44 45 <Button 46 android:layout_width="wrap_content" 47 android:layout_height="wrap_content" 48 android:text="×" 49 android:id="@+id/multiButton" 50 android:layout_row="2" 51 android:layout_column="5" /> 52 53 <Button 54 android:layout_width="wrap_content" 55 android:layout_height="wrap_content" 56 android:text="BS" 57 android:id="@+id/backSpaceButton" 58 android:layout_row="2" 59 android:layout_column="7" /> 60 61 <Button 62 android:layout_width="wrap_content" 63 android:layout_height="wrap_content" 64 android:text="7" 65 android:id="@+id/num7Button" 66 android:layout_row="3" 67 android:layout_column="1" /> 68 69 <Button 70 android:layout_width="wrap_content" 71 android:layout_height="wrap_content" 72 android:text="8" 73 android:id="@+id/num8Button" 74 android:layout_row="3" 75 android:layout_column="3" /> 76 77 <Button 78 android:layout_width="wrap_content" 79 android:layout_height="wrap_content" 80 android:text="9" 81 android:id="@+id/num9Button" 82 android:layout_row="3" 83 android:layout_column="5" /> 84 85 <Button 86 android:layout_width="wrap_content" 87 android:layout_height="wrap_content" 88 android:text="-" 89 android:id="@+id/minusButton" 90 android:layout_row="3" 91 android:layout_column="7" /> 92 93 <Button 94 android:layout_width="wrap_content" 95 android:layout_height="wrap_content" 96 android:text="4" 97 android:id="@+id/num4Button" 98 android:layout_row="4" 99 android:layout_column="1" /> 100 101 <Button 102 android:layout_width="wrap_content" 103 android:layout_height="wrap_content" 104 android:text="5" 105 android:id="@+id/num5Button" 106 android:layout_row="4" 107 android:layout_column="3" /> 108 109 <Button 110 android:layout_width="wrap_content" 111 android:layout_height="wrap_content" 112 android:text="6" 113 android:id="@+id/num6Button" 114 android:layout_row="4" 115 android:layout_column="5" /> 116 117 <Button 118 android:layout_width="wrap_content" 119 android:layout_height="wrap_content" 120 android:text="+" 121 android:id="@+id/addButton" 122 android:layout_row="4" 123 android:layout_column="7" /> 124 125 <Button 126 android:layout_width="wrap_content" 127 android:layout_height="wrap_content" 128 android:text="1" 129 android:id="@+id/num1Button" 130 android:layout_row="5" 131 android:layout_column="1" /> 132 133 <Button 134 android:layout_width="wrap_content" 135 android:layout_height="wrap_content" 136 android:text="2" 137 android:id="@+id/num2Button" 138 android:layout_row="5" 139 android:layout_column="3" /> 140 141 <Button 142 android:layout_width="wrap_content" 143 android:layout_height="wrap_content" 144 android:text="3" 145 android:id="@+id/num3Button" 146 android:layout_row="5" 147 android:layout_column="5" /> 148 149 <Button 150 android:layout_width="wrap_content" 151 android:layout_height="wrap_content" 152 android:text="=" 153 android:id="@+id/equalButton" 154 android:layout_row="5" 155 android:layout_column="7" 156 android:layout_rowSpan="2" 157 android:enabled="true" 158 android:singleLine="false" 159 android:layout_gravity="fill_vertical" /> 160 161 <Button 162 android:layout_width="wrap_content" 163 android:layout_height="wrap_content" 164 android:text="0" 165 android:id="@+id/num0Button" 166 android:layout_row="6" 167 android:layout_column="1" /> 168 169 <Button 170 android:layout_width="wrap_content" 171 android:layout_height="wrap_content" 172 android:text="." 173 android:id="@+id/piriodButton" 174 android:layout_row="6" 175 android:layout_column="3" /> 176 177 <Button 178 android:layout_width="wrap_content" 179 android:layout_height="wrap_content" 180 android:text="±" 181 android:id="@+id/signButton" 182 android:layout_row="6" 183 android:layout_column="5" /> 184 185 </GridLayout> 186 187</RelativeLayout>

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

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

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

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

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

guest

回答1

0

ベストアンサー

RerativeLayoutはandoroidでは邪道なイメージです。
基本LinearLayoutが簡単に構築できます。
LinearLayoutは上から順次構築するLayoutです。
これは推測ですがRerativeLayoutの為Textがボタンと重なるからGridViewに入れたのだと思われます。
その原因で複雑になって高さや幅が画面以上になっているのだと思います。
プログラムはなるべく単純の方が良いです。

単純な電卓構築は

<LinerLayout
<TextView(表示したい高さ幅は指定した方が良い)
<GridView(4*4)
<Button設置/>
/>
/>

で簡単に下のような電卓が作れると思います。

text
789÷
456×
123-
0 =+

GridViewはrow columnは0から開始だったはずなので1行1列は(0,0)です。
上の電卓の場合7が(0,0)になります。
もし隙間の為に1列目を残してるのであればpaddingかmarginで調整すると良いでしょう。

投稿2015/06/02 15:56

miso

総合スコア68

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

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

yojouhan

2015/06/03 04:50

ご教授ありがとうございます。 無事表示の問題も解決致しました。 なるほど、外側のRerativeLayoutが悪さをしていたのですね… (GridViewを入れた経緯もご推察の通りです…) また、GridViewの扱いについても丁寧に解説して頂きありがとうございます。 大変参考になります。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.49%

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

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

質問する

関連した質問