Androidのレイアウトで画像の横に複数行のテキストを配置したい

このQ&Aのポイント
  • Androidのレイアウトで画像の横に複数行のテキストを配置する方法について質問です。
  • 現在、TableLayoutを使用しているがうまく配置できない状況であり、AbsoluteLayoutも使えないことが分かっており困っています。
  • どのようにしたら、画像の横に複数行のテキストを配置することができるでしょうか?ご教授ください。
回答を見る
  • ベストアンサー

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
  • 回答数1
  • ありがとう数4

質問者が選んだベストアンサー

  • ベストアンサー
  • droidkun
  • ベストアンサー率85% (6/7)
回答No.1

添付画像が見えないので想像ですが下じゃダメですか? ※SDK2.2以上 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="fill_parent" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:layout_height="wrap_content" android:id="@+id/imageView1" android:src="@drawable/icon" android:layout_width="wrap_content"></ImageView> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:text="ながいもじながいもじながいもじながいもじながいもじ1行目" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <TextView android:text="ながいもじながいもじながいもじながいもじながいもじ2行目" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> </LinearLayout> </LinearLayout>

nstammy507
質問者

お礼

回答ありがとうございます。 なんとか似たような感じになりました 笑顔 でも私のEclipseの環境でmatch_parentがエラーなっちゃいました 泣 android:layout_width="match_parent" android:layout_height="fill_parent" なんか意味があるのでしょうが、混在していたので疑問でした。 私の浅い認識ではfill_parent→match_parentに移行された・・・みたいに覚えていましたので・・・ と、言っても私の環境でmatch_parentがエラー出てたので、無視してfill_parent使ってましたけど 苦笑 取り敢えず無事イメージしていたレイアウトになったので感謝感謝です ありがとうございました。

関連するQ&A

  • Androidの画面レイアウトがくずれます

    同じサイズの画像を並べても、シミュレータで表示するとばらばらのサイズになってしまいます。 もう1ヶ月以上解決できなくて困っています。 写真はXMLベースで4つの画像を表示した結果です。 シミュレータでやってもほぼ同じ結果です。 元々の画像では、茶色と緑が同じ幅で、ピンクと青が同じ幅です。4つの画像とも高さは一緒です。 サイズの変更等はしてません。 GraphicalLayoutoは5.1inWVGA、シミュレータはWVGA854、Android2.3.3です ソースです。 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/left"/> <LinearLayout android:id="@+id/center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/left" android:orientation="vertical"> <ImageView android:id="@+id/top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/top"/> <ImageView android:id="@+id/bottom" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/bottom"/> </LinearLayout> <ImageView android:id="@+id/right" android:layout_height="wrap_content" android:src="@drawable/right" android:layout_toRightOf="@+id/center"/> </RelativeLayout>

  • androidプログラムのエラーについて

    自分は今、本を読みながらandroidプログラミングの勉強をしています。 XMLファイルをよく見直して間違いは見当たらないのですが 起動しようとすると「your project contains error」と表示されます。 コンソールには「No resource found that matches the given name (at 'title' with value '@string/menu_settings')」と書いてあります。 ネットで調べたらソースをクリーンすればいいと書いてありましたが クリーンすると今度はjavaファイルにエラーが起きます。 以下が自分が打ち込んだ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:text="お申込みフォーム" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:text="お名前 :" android:layout_width="70sp" android:layout_height="wrap_content"/> <EditText android:id="@+id/name" android:layout_width="200dp" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:text="住所 :" android:layout_width="70sp" android:layout_height="wrap_content"/> <EditText android:id="@+id/address" android:layout_width="200dp" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:text="生年月日 :" android:layout_width="70sp" android:layout_height="wrap_content"/> <Spinner android:id="@+id/month" android:entries="@array/month" android:layout_width="85dp" android:layout_height="wrap_content"/> <TextView android:text="月" android:layout_width="20sp" android:layout_height="wrap_content"/> <Spinner android:id="@+id/day" android:entries="@array/day" android:layout_width="85dp" android:layout_height="wrap_content"/> <TextView android:text="日" android:layout_width="20sp" android:layout_height="wrap_content"/> </LinearLayout> </LinearLayout> どうかよろしくお願い致します。

  • Android開発についての初心者質問です。

    Android開発についての質問です。初心者でAndroidアプリを作っています。 初心者でAndroidアプリを作っています。 XMLからの実装をしたいのですが、 やり方がよく分かりません。 どなたかご教授頂けないでしょうか? よろしくお願いいたします。 やりたいことは、imageButtonをクリックしたら imageViewの画像部分が変わる。 imageButton1をクリック → imageView1が表示 imageButton2をクリック → imageView2が表示 デフォルトでは、imageView1が表示している状態 buttonのリスナーを登録するのが関の山で、ボタンクリック時の imageView表示切替処理等ちんぷんかんぷんです。 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="wrap_content"> <FrameLayout android:id="@+id/frameLayout1" android:layout_height="wrap_content" android:foregroundGravity="center" android:layout_width="match_parent" > <ImageView android:layout_height="wrap_content" android:src="@drawable/icon" android:id="@+id/imageView1" android:layout_gravity="center" android:layout_width="match_parent" > </ImageView> </FrameLayout> <LinearLayout android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_width="match_parent" > <ImageButton android:id="@+id/imageButton1" android:layout_height="wrap_content" android:src="@drawable/icon" android:layout_width="wrap_content" > </ImageButton> <ImageButton android:id="@+id/imageButton2" android:layout_width="wrap_content" android:src="@drawable/icon" android:layout_height="wrap_content" > </ImageButton> <ImageButton android:id="@+id/imageButton3" android:layout_width="wrap_content" android:src="@drawable/icon" android:layout_height="wrap_content" > </ImageButton> </LinearLayout> </LinearLayout>

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

    XMLで作成したTextViewを処理中に色を変えることは出来ないのでしょうか? 下記のようにやれば実装できるのでは?と思ってやってみましたがダメでした、 XMLファイルを使った方法で文字の色を変更する事は可能ですか? hogehoge.xml---------------------------------------------- <TextView android:id="@+id/text" android:textColor="@color/black" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="hogehoge" /> hogehoge.java--------------------------------------------- EditText textView=(EditText)findViewById(R.id.text); textView.setTextColor(Color.RED); ---------------------------------------------------------

  • 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 HashMapについて助言お願いし

    初心者ですが、どうぞ宜しくお願いします。 下記コードでは、マップに 「 map.put( "Key1", "val1" ); map.put( "key2", "val2" ); 」を追加しているのですが、このデータをキーから取り出しテキストビューに表示しようとしています。 このままではエラーはないのですが、何も表示されない状況です。 初心者の無知な質問となりますが、 テキストビューへの表示方法はどのようにすればよいのでしょうか? 何か別の方法でもよいので、ご教授宜しくお願いいたします。 -------------------------------------------------------------------- <?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:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv1"></TextView> </LinearLayout> ------------------------------------------------------------ package com.test; import java.util.HashMap; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //1)HashMapからMapのインスタンスを生成 HashMap<String, String> map = new HashMap<String, String>(); // キーと値のペアを格納 map.put( "Key1", "val1" ); map.put( "key2", "val2" ); // 指定したキーに対応する値を取得. String val = (String)map.get( "key1" ); // テキストビュー取得 TextView tv = (TextView)findViewById(R.id.tv1); tv.setText(val); } }

    • ベストアンサー
    • Java
  • android TableLayout使用時で

    いつもお世話になっています。 android TableLayout使用時のことで質問します。 forでTextViewに値を入れていきたいのですが、このときxmlでTextViewをひとつ作っておいてそのTextViewを使いまわすことはできないのでしょうか? したいのが、 for文で、TableRowに値を入れていきたい。 private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT; private final int FP = ViewGroup.LayoutParams.FILL_PARENT; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); TableLayout tableLayout = new TableLayout(this); setContentView(tableLayout); for(int a=0;a<3;a++){ TextView text1 = new TextView(this); text1.setText("user"); TableRow tableRow1 = new TableRow(this); tableRow1.addView(text1); tableLayout.addView(tableRow1, createParam(FP, WC)); } } private TableLayout.LayoutParams createParam(int w, int h){ return new TableLayout.LayoutParams(w, h); } この時表示されたのが、 user user user この方法を、xmlのTextViewを呼ぶ形で実現したいのですが、 xmlでは、 <TableRow> ↓ このTextViewを使いまわしたい。 <TextView android:id="@+id/user" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="Test"> </TextView> </TableRow> で、表記しています。 xmlでは、普通に先に記述していないと使えないのでしょうか? つまり、もしTableにTextViewを3つ使いたいなら、TextViewを既に3つ記述していないと使えないものなのでしょうか? よろしくお願いします。

    • ベストアンサー
    • Java
  • マップとボタン同時表示|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>

  • 目的のシークバー表示されなく別のシークバー表示

    EclipseのAndroid プログラム作成で目的のシークバー1(画像添付 参照)表示されなく、別のシークバー2(別(画像添付 参照)が表示される。 質問 1 目的のシークバー1(画像添付)を表示されなく、別のシークバー2が表示(画像添付)される理由を教えてください。  質問 2 目的のシークバー1(画像添付) を表示される方法を教えてください。 ○動作環境項目  O S : windows8.1 Eclipse :eclipse KEPLER servicie Release 2 Androidバージョン:  Android 4.2.2 ○目的シークバー   (画像添付) シークバー1 ○別のシークバー   (画像添付) シークバー2 ○XMLコード(Main.xml)  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="バーをドラッグしてください。" /> <SeekBar android:id="@+id/seekBar1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingRight="20px" android:max="100" /> </LinearLayout>

  • Android用のアプリケーション開発

    私は下記の開発環境でAndroid用のアプリケーションを開発しています。 Eclipse Version: 3.6.2 Android 2.3.3 TableLayoutで3行3列のテーブルの、4行目の3列目と5行目の3列目を結合したいですが出来ませんでした。 下記のソースコードの「あいうえおかきくけ」の部分を画像にして2行分の大きさで表示させたいです。 Android用のアプリケーションの開発が初めてですが、ご教授を頂けると幸いです。 下記はソースコードの一部です。 --------------------------------------- //1行目 TextView text1 = new TextView(this); text1.setText("         "); TextView text2 = new TextView(this); text2.setText("投資情報"); TextView text3 = new TextView(this); text3.setText("         "); TableRow tableRow1 = new TableRow(this); tableRow1.addView(text1); tableRow1.addView(text2); tableRow1.addView(text3); tableLayout.addView(tableRow1, createParam(FP, WC)); //2行目 TextView text4 = new TextView(this); text4.setText("先週の情報"); TableRow tableRow2 = new TableRow(this); tableRow2.addView(text4); tableLayout.addView(tableRow2, createParam(FP, WC)); //3行目 TextView text8 = new TextView(this); text8.setText("2011年11月7日"); text8.setWidth(480); text8.setGravity(Gravity.RIGHT); TableRow tableRow3 = new TableRow(this); TableRow.LayoutParams rowLayout3 = new TableRow.LayoutParams(); rowLayout3.span = 3; tableRow3.addView(text8, rowLayout3); tableLayout.addView(tableRow3, createParam(FP, WC)); //4行目 ImageView image1 = new ImageView(this); image1.setImageResource(R.drawable.tyuugoku); TextView text11 = new TextView(this); text11.setText("国名"); TextView text12 = new TextView(this); text12.setText("あいうえおかきくけ"); TableRow tableRow4 = new TableRow(this); TableRow.LayoutParams rowLayout4 = new TableRow.LayoutParams(); rowLayout4.column = 2; tableRow4.addView(image1); tableRow4.addView(text11); tableRow4.addView(text12); tableLayout.addView(tableRow4, createParam(FP, WC)); //5行目 TextView text13 = new TextView(this); text13.setText("記事リード"); TableRow tableRow5 = new TableRow(this); TableRow.LayoutParams rowLayout5 = new TableRow.LayoutParams(); tableRow5.addView(text13); tableLayout.addView(tableRow5, createParam(FP, WC)); ---------------------------------------- 長文になりましたが、どうぞ宜しくお願い致します。

    • ベストアンサー
    • Java

専門家に質問してみよう