• 締切済み

Android javaでのTextView

Android javaの質問です。 よろしければ教えてください。 レイアウト構成として、一番上にボタン、中央にテキストビュー、一番下にボタン。 といった感じです。 ボタンの配置はうまくいくのですが、テキストビューがうまく配置されません。 というのも、ここでは省略して書いてませんが、テキストBOXにて文字が入力されたらテキストビューに表示される。 といった仕組みですが、上下のボタンの上に文字が重なってしまいます。 ですので、テキストビュー範囲をを上下ボタンまでとしたいです。 できれば、文字表示も入力されたらLINEのように下から上へと表示されるようにしたいです。 -------省略-------- final int ID_TOP = 1; final int ID_CENTER =2; final int ID_BOTTOM = 3; RelativeLayout layout = new RelativeLayout(this); //上ボタン Button btnTop = new Button(this); btnTop.setId(ID_TOP); btnTop.setText("Top"); RelativeLayout.LayoutParams prmTop = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); prmTop.addRule(RelativeLayout.ALIGN_PARENT_TOP); btnTop.setLayoutParams(prmTop); layout.addView(btnTop); //テキストビュー lblReceive=new TextView(this); lblReceive..setId(ID_CENTER); lblReceive.setText(""); lblReceive.setTextSize(16.0f); lblReceive.setTextColor(Color.rgb(0,0,0)); RelativeLayout.LayoutParams prmCenter = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); prmCenter.addRule(RelativeLayout.CENTER_IN_PARENT); btnCenter.setLayoutParams(prmCenter); layout.addView(lblReceive) //下ボタン Button btnBottom = new Button(this); btnBottom.setId(ID_BOTTOM); btnBottom.setText("Bottom"); RelativeLayout.LayoutParams prmBottom = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); prmBottom.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); btnBottom.setLayoutParams(prmBottom); layout.addView(btnBottom); -------省略-------- よろしくお願いします。

  • Java
  • 回答数1
  • ありがとう数0

みんなの回答

  • anmochi
  • ベストアンサー率65% (1332/2045)
回答No.1

テキストボックスはどこにあるの? 下のボタンを押したら出てくる感じかな? こういうレイアウト(上下固定で真ん中をあまりの部分として)はRelativeLayoutじゃなくてLinearLayoutを使うのが簡単便利楽で得だ。 こういう風にすると良いでしょう。これで、真ん中のログにどんどんテキストが追加されていき、溢れた時でも下のボタンに食い込まず、かつログ部分はログ部分でスクロールができるようになるぜ。テキストが下から上は分からないな。何か手はあるんだろうけど。 LinearLayout | +-Button(上のボタン) Height: WARP_CONTENT、Weight: 0 | +-ScrollView(真ん中のログのプレースホルダー) Height: WARP_CONTENT、Weight: 1 | | | +-TextView(真ん中のログ) Height: MATCH_PARENT | +-Button(下のボタン) Height: WARP_CONTENT、Weight: 0

関連するQ&A

  • Androidでこのエラーを解決したいです

    どなたかご教授お願いします package com.example.kusogame; import宣言省略 public class TypingKusoGame extends Activity { /** Called when the activity is first created. */ public TextView txtInfo; public EditText edtText; public Button outputbutton; public Button createtext; public TextView txtResult; public TextView Title; public TextView txtjudge; public String strInch; public String gettext; public String test = "check"; public ImageView judgecat; public int idx = 0; private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT; public int createParam; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //レイアウト作成 ここから LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //レイアウトを見えるようにする //レイアウト作成 ここまで //GUI部品作成 ここから //タイトル Title = new TextView(this); Title.setText("Let's Training!"); Title.setTypeface(Typeface.DEFAULT_BOLD); Title.setTextScaleX(1.5f); Title.setTextColor(Color.rgb(255,0,0)); layout.addView(Title); // ラベル txtInfo = new TextView(this); txtInfo.setText("check"); txtInfo.setTextScaleX(1.5f); strInch = ("check"); layout.addView(txtInfo); // エディタ edtText = new EditText(this); layout.addView(edtText); // ボタン txtResult = new Button(this); txtResult.setText("same or difference"); layout.addView(txtResult); // 結果表示用ラベル txtjudge = new TextView(this); txtjudge.setText("check"); layout.addView(txtjudge); //結果表示用猫ラベル judgecat = new ImageView(this); judgecat.setImageResource(R.drawable.failed); LinearLayout.addView(judgecat,LayoutParams(WC)); ~~~~~~~~~~~~~~このエラーが解決できません メソッドLayoutParam(int)は 型TypingKusoGameで未定義です //GUI部品作成 ここまで txtResult.setOnClickListener(new OnClickListener(){ pub

    • ベストアンサー
    • Java
  • androidでアプリを作ろうとしてるのですが

    package com.example.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; public class InOutTest extends Activity { /** Called when the activity is first created. */ public TextView txtInfo; public EditText edtText; public Button outputbutton; public TextView txtResult; public TextView txtjudge; public String strInch; public String gettext; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //レイアウト作成 ここから LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //レイアウトを見えるようにする //レイアウト作成 ここまで //GUI部品作成 ここから // ラベル txtInfo = new TextView(this); txtInfo.setText("check"); strInch = ("check"); layout.addView(txtInfo); // エディタ edtText = new EditText(this); layout.addView(edtText); // ボタン txtResult = new Button(this); txtResult.setText("same or difference"); layout.addView(txtResult); // 結果表示用ラベル txtjudge = new TextView(this); txtjudge.setText("check"); layout.addView(txtjudge); //GUI部品作成 ここまで txtResult.setOnClickListener(new OnClickListener(){ public void onClick(View v) { gettext = edtText.toString(); if (strInch==gettext){ txtjudge.setText("ok"); } }; }); }} 上のプログラムで strInchに入ってるデータとgettextで取得した文章を比較して同じなら txtjudgeにOKと引き渡して表示させたいのですがうまく動きません 何方かどうぞよろしくお願い致します

    • ベストアンサー
    • Java
  • android TableLayoutの子要素

    初心者ですが、どうぞ宜しくお願いいたします! 下記のようにサンプルコードを自分なりにいじってTableLayoutに要素を入れてみました。 このTableLayoutの子要素のTableRowとTextViewをボタンクリックで全削除するようにしたいのですが、どのように記述すれば良いでしょうか? リストビューにClear()メソッドのように簡単に初期化することはできないでしょうか? 拙い説明ですが、お力添え宜しくお願いいたします。 int Line = 10;// 行要素数 int T_ROW = 5;// 列要素数 // Rowを入れるTableLayout TableLayout table = (TableLayout) findViewById(R.id.t); table.setBackgroundColor(Color.BLACK); // TableRow用 TableRow row; TableRow.LayoutParams row_layout_params = new TableRow.LayoutParams(-2, -2); // -2はLayoutParams.WRAP_CONTENT // TextView用 TextView[] array_text_view = new TextView[10]; TableRow.LayoutParams text_layout_params = new TableRow.LayoutParams(-2, -2); // -2はLayoutParams.WRAP_CONTENT text_layout_params.weight = 1; //プロパティ直接書き換え for(int y = 0; y < Line; ++y){ // 行 // 行ごとにRowの初期化 row = new TableRow(this); row.setLayoutParams(row_layout_params); for(int x = 0; x < T_ROW; ++x){ // 列 int index = x + y * 5; // TextViewの設定をして array_text_view[index] = new TextView(this); array_text_view[index].setLayoutParams(text_layout_params); //array_text_view[index].setText("Text" + Integer.toString(index)); array_text_view[index].setText(price_lst.get(index + 1)); ShapeDrawable shape=new ShapeDrawable(new RectShape()); shape.getPaint().setStyle(Paint.Style.STROKE); array_text_view[index].setBackgroundDrawable(shape); array_text_view[index].setTextColor(Color.BLACK); array_text_view[index].setPadding(10, 10, 10, 10);//文字の前後左右に空白 row.setBackgroundColor(Color.WHITE); if (index == 0 || index == 1 || index == 2 || index == 3 || index == 4) { array_text_view[index].setTextColor(Color.BLACK); array_text_view[index].setPadding(10, 10, 10, 10); //テーブルの題名表記色の変更 row.setBackgroundColor(Color.YELLOW); } // rowに入れていく row.addView(array_text_view[index]); } // 1行入れて次のループへ table.addView(row); } }

  • Androidのレイアウトについて

    こんばんは ちょっとアンドロイドのレイアウトでちょっと戸惑って質問来ました。 添付画像のように画像の横のテキストを2行(本来は右より)で配置したいのですが、うまく設定出来ません。 TableLayoutをどういじってもダメ 泣 AbsoluteLayoutを見つけましたが、上部のテキストが長い時に使えない事がわかりどうしようもありません。 どのようにしたら、画像の横にテキスト行をニ行置けるでしょうか? <TableLayout android:layout_height="wrap_content" android:id="@+id/tableLayout1" android:layout_width="fill_parent"> <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:id="@+id/imageView1" android:src="@drawable/icon" android:layout_height="wrap_content"></ImageView> <LinearLayout android:id="@+id/linearLayout5" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:text="TextView" android:layout_width="wrap_content" android:id="@+id/textView5" android:layout_height="wrap_content"></TextView> </LinearLayout> <TextView android:text="TextView" android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> </TableRow> </TableLayout> 取り敢えず今の問題の所が上です。 【知りたい事】 画像の横にニ行以上テキストを配置したい。 【やった事】 いろいろやり過ぎて書ききれません 泣 【開発環境】 Eclipse 何卒お知恵を貸してください。お願します。

    • ベストアンサー
    • XML
  • androidプログラミングについての質問

    このプログラムについて質問したいのですが public class InOutTest extends Activity { /** Called when the activity is first created. */ public TextView txtInfo; public EditText edtText; public Button outputbutton; public TextView txtResult; public TextView txtjudge; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //レイアウト作成 ここから LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //レイアウトを見えるようにする //レイアウト作成 ここまで //GUI部品作成 ここから // ラベル txtInfo = new TextView(this); txtInfo.setText("check spell same or not:"); layout.addView(txtInfo); // エディタ edtText = new EditText(this); layout.addView(edtText); // ボタン txtResult = new Button(this); txtResult.setText("same or difference"); layout.addView(txtResult); // 結果表示用ラベル txtjudge = new TextView(this); txtjudge.setTextSize(30f); layout.addView(txtjudge); //GUI部品作成 ここまで txtResult.setOnClickListener(new OnClickListener(){ public void onClick(View v) { String strInch = ""; if (edtText==txtInfo) strInch = "typed as same"; txtResult.setText(strInch); } }); } } txtResultに文章を引き渡して表示させたいのですが やり方が分かりません お時間のある方でいいので どなたかよろしければ教えてください

  • Android開発 Eclipse(超初心者)

    Eclipseの使い方がわかりません。 eclipseをインストールしてプロジェクトを作成しAVDの仮想デバイスを適当に作成し AVD仮想デバイス ターゲット:Android4.0-APILevel14 SDカード:サイズ 66MiB スキン:ビルトイン WVGA800 package com.example.android.hello.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; public class Hello15 extends Activity{ //表示用のテキストとボタンを宣言 --- private TextView txtCaption; private Button btnHello; public void OnCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); //レイアウトを作成 LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //テキストを追加 txtCaption = new TextView(this); txtCaption.setText("Click Button!"); layout.addView(txtCaption); //ボタンを追加 btnHello = new Button(this); btnHello.setText("Button"); layout.addView(btnHello); //イベントを設定 btnHello.setOnClickListener(new OnClickListener(){ public void onClick(View v){ txtCaption.setText("Hello, Android!"); } }); } } サンプルで上記のようなソースを作成して 実行したのですが 以前は Android Application Java Applet Java Application など選択肢が出てたのですが仮想デバイスを設定した 辺りからでなくなり実行して少し経つと ←画面に『android』という文字が →画面にキーボードのようなものがでてきて 3分ぐらいまつと←画面が携帯画面に変化します 上記のプログラムではボタンの生成とメッセージがでてくるはずが それらしきものがありません。これらはどこに出てくるのでしょうか? 動かし方すらよくわかってないのでお解説おねがいいたしもうす;

  • マップとボタン同時表示|AndroidStudio

    下記のサイトを参考にしてボタンとマップを同時に表示させるxmlを記述したつもりなのですが、 実行すると一瞬だけボタンが映り、その後はマップのみが表示されました。 https://groups.google.com/forum/?hl=ja&fromgroups#!topic/shikokugtug/NGseYmNKQQQ 何がおかしいのでしょうか。 記述したxmlは以下の通りです。 ちなみにfragmentをwrap_contentに変更しても同じでした。 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.example.~.MapsActivity" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.SupportMapFragment" /> <LinearLayout android:id="@+id/level" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/large_up" android:text="@string/large_up" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/large_down" android:text="@string/large_down" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/small_down" android:text="@string/small_down" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/small_up" android:text="@string/small_up" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </FrameLayout>

  • 作成中のandroidアプリにタイマを組み込みたい

    カウントダウンタイマーを現在作成中のアプリに組み込みたいのですが 調べてもイマイチやり方が分からないでいます 秒数は固定でもいいのでなるべく単純なものをお願いします 作成中のプログラムは以下に記述しておきます 使えるページと組み込みの手順を何方かご教授くださいませ もし私のプログラムを使いたいという方がいらっしゃいましたらどうぞご自由に 文字制限の関係で一部省略 package com.example.kusogame; import *省略 public class TypingKusoGame extends Activity { /** Called when the activity is first created. */ public 宣言省略 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //レイアウト作成 ここから LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); setContentView(layout); //レイアウトを見えるようにする //レイアウト作成 ここまで //GUI部品作成 ここから //タイトル Title = new TextView(this); Title.setText("Let's Training!"); layout.addView(Title); // ラベル txtInfo = new TextView(this); txtInfo.setText("check"); strInch = ("check"); layout.addView(txtInfo); // エディタ edtText = new EditText(this); layout.addView(edtText); // ボタン txtResult = new Button(this); txtResult.setText("same or difference"); layout.addView(txtResult); // 結果表示用ラベル txtjudge = new TextView(this); txtjudge.setText("check"); layout.addView(txtjudge); //GUI部品作成 ここまで txtResult.setOnClickListener(new OnClickListener(){ public void onClick(View v) { gettext = edtText.getText().toString(); if (gettext.equals(test)){ txtjudge.setText("ok"); switch(idx){// サンプル文の生成 case 0: txtInfo.setText("copyit"); test ="copyit"; break; case 1: txtInfo.setText("androidboy"); test ="check"; break; case 2: txtInfo.setText("laugh"); test ="laugh";break; case 3: txtInfo.setText("training"); test ="training"; break; default : //添字のリセット txtInfo.setText("reset"); test ="reset"; idx = 0; break; } idx += 1; //添字を1増やす }else{txtjudge.setText("no!");} }; }); } }

    • ベストアンサー
    • Java
  • androidのサンプルソースについての質問

    このページを参考に学習をしていたのですが http://libro99.appspot.com/index3?id=29&page=2&label=android .javaに追加するぶぶんで text.setText(selradio.getText()); ~~~~ の波線の部分のエラーをどうしても消すことができず 困っています package test.radiobutton; import android.app.Activity; import android.os.Bundle; import android.widget.RadioButton; import android.widget.RadioGroup; public class radiobuttontest extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); RadioGroup group = (RadioGroup)this.findViewById(R.id.group); RadioButton radio1 = (RadioButton)this.findViewById(R.id.radio1); RadioButton radio2 = (RadioButton)this.findViewById(R.id.radio2); radio2.setChecked(true); int selid = group.getCheckedRadioButtonId(); RadioButton selradio = (RadioButton)this.findViewById(selid); text.setText(selradio.getText()); } } main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <RadioGroup android:id="@+id/group" android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:text="@string/radio1_label" android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RadioButton android:text="@string/radio2_label" android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RadioGroup> </LinearLayout> これ以上はかけませんがページの指示通りにやってるつもりです どなたかご教授お願いします

    • ベストアンサー
    • Java
  • AndroidアプリのViewのサイズ変更

    Androidアプリの開発をしています。 Viewの幅と高さを画面サイズなどに合わせて変更したいです。 LayoutのXMLで作成した各Viewを後からサイズ変更はできないのでしょうか? サンプルソースを見ると、コード上でViewを作成・追加しているものしかなかったので、そうなのかなと。。。 +-------- | |ListView | +-------- |Button +-------- こんな感じで画面に一覧とボタンを配置したいのです 全体をRelativeLayoutにして一覧をTOP、ボタンを入れたLinearLayoutをBOTTOMに指定しています。 ListViewの高さをWRAPに指定していたのですが自動で画面の高さ-ボタンの高さにはしてくれませんでした。 なので、自分でやるしかないのかな?という状況です。 各Viewのサイズが決定した後(onWindowFocusChangedあたり?)でListViewを高さ計算して作成する ・・・めんどくさい(笑) いい方法があったら教えてください。

専門家に質問してみよう