Androidの画面レイアウトがくずれます
- 同じサイズの画像を並べても、シミュレータで表示するとばらばらのサイズになってしまいます
- 写真はXMLベースで4つの画像を表示した結果です。シミュレータでやってもほぼ同じ結果です
- 元々の画像では、茶色と緑が同じ幅で、ピンクと青が同じ幅です。4つの画像とも高さは一緒です。サイズの変更等はしてません
- ベストアンサー
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>
- yuki-goo00
- お礼率14% (7/50)
- Android
- 回答数1
- ありがとう数1
- みんなの回答 (1)
- 専門家の回答
質問者が選んだベストアンサー
まあ、一言で言えば 「ADTのレイアウトエディタはショボいのでマトモに表示されない」 のです。なので気にしてはいけません。 レイアウトエディタの表示は参考にとどめ、エミュレータや実機で実際に出してみるしか、意図通りに正しく表示されているかどうかを確認する術はありません。 将来的には修正されるかもしれませんが、現時点で開発している開発者は、うまくやりくりして、工夫してやっていくしか無いですね。
関連するQ&A
- 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開発についての初心者質問です。
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プログラムのエラーについて
自分は今、本を読みながら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の間違い探しアプリを作ろうと思っています。 イメージ的には背景用のImageViewに画像を表示して、 間違っている箇所にカラのImageViewを載せ、 ImageViewがクリックされたら正解というような仕組みにしようと思っています。 そこで、下記コードを書いています。 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_vertical" > <ImageView android:id="@+id/mainImage" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/stage1" ></ImageView> <ImageView android:id="@+id/onImage" android:layout_width="40dip" android:layout_height="40dip" android:layout_marginLeft="240dp" android:layout_marginTop="180dp" android:onClick="seikai" /> </RelativeLayout> が、解像度や画面サイズによってカラのImageViewの場所が変わってしまい、うまくいきません。 resフォルダ内に 「layout-land-hdpi」 「layout-land-ldpi」 「layout-land-mdpi」 「layout-land-xhdpi」 フォルダを作り、解像度ごとに位置の微調整は行なっていますが、 画面サイズが異なるとやはりずれてしまいます。 解像度、画面サイズにかかわらず位置を固定する方法はないのでしょうか。 ない場合はやはり画面サイズと解像度すべての条件のxmlを作成する必要がありますか。 また、そもそも 「イメージ的には背景用のImageViewに画像を表示して、間違っている箇所にカラのImageViewを載せる」やり方が間違っているのでしょうか。
- 締切済み
- 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>
- 締切済み
- スマートフォンアプリ開発
- 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
- 学校の課題でアンドロイドアプリを作っています。
カメラをアプリを使ったアプリなのですが、 http://techbooster.jpn.org/andriod/application/295/さんのサイトのソースを改良して アプリを作ろうと思っています。 <SurfaceView android:id="@+id/surface_view" android:layout_width="100dp" android:layout_height="wrap_content" /> </LinearLayout> のように横幅を変えたとき、今のままだと狭くなったSurfaceViewに プレビュー画像が圧縮されてしまいます。 どのようにすれば、圧縮されずに映っていないところ以外を そのままのサイズで表示できるのでしょうか? いろいろ調べたのですがわかりません。
- 締切済み
- Java
- 学校の課題でアンドロイドアプリを作っています。
カメラをアプリを使ったアプリなのですが、 http://techbooster.jpn.org/andriod/application/295/さんのサイトのソースを改良して アプリを作ろうと思っています。 <SurfaceView android:id="@+id/surface_view" android:layout_width="100dp" android:layout_height="wrap_content" /> </LinearLayout> のように横幅を変えたとき、今のままだと狭くなったSurfaceViewに プレビュー画像が圧縮されてしまいます。 どのようにすれば、圧縮されずに映っていないところ以外を そのままのサイズで表示できるのでしょうか? いろいろ調べたのですがわかりません。
- 締切済み
- Android
- 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
- android javaについて質問です
android javaについて質問です public class MailMotion extends Activity implements OnTouchListener, OnClickListener { private FrameLayout frameLayout01; private ImageView target; private Button trash; private int targetLocalX; private int targetLocalY; private int screenX; private int screenY; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.motion); frameLayout01 = (FrameLayout)findViewById(R.id.FrameLayout01); target = (ImageView)findViewById(R.drawable.toudai); target.setOnTouchListener(this); trash = (Button)findViewById(R.id.trash); trash.setOnClickListener(this); } @Override public boolean onTouch(View v, MotionEvent event) { int x = (int)event.getRawX(); int y = (int)event.getRawY(); switch(event.getAction()) { case MotionEvent.ACTION_DOWN: targetLocalX = target.getLeft(); targetLocalY = target.getTop(); screenX = x; screenY = y; break; case MotionEvent.ACTION_MOVE: int diffX = screenX - x; int diffY = screenY - y; targetLocalX -= diffX; targetLocalY -= diffY; target.layout(targetLocalX, targetLocalY, targetLocalX + target.getWidth(); targetLocalY + target.getHeight()); screenX = x; screenY = y; break; case MotionEvent.ACTION_UP: int trashLeft = trash.getLeft() + trash.getWidth()/2; int trashTop = trash.getTop() + trash.getHeight()/2; int targetRight = target.getLeft() + target.getWidth(); int targetBottom = target.getTop() + target.getHeight(); if (targetRight > trashLeft && targetBottom > trashTop) { frameLayout01.removeView(target); } break; } return true; } @Override public void onClick(View v) { int childCount = frameLayout01.getChildCount(); if(childCount == 1) { frameLayout01.addView(target); }}} 上記のものを起動させると、nullpointが出てきます 前回の質問をもとに、デバッグをしてみたのですが、touchonLisnerのところでエラーが起きました 勉強不足なので原因がよくわかっておりません 間違いを教えていただけないでしょうか? stringは <drawable name="custom_button">#ffff00</drawable> で設定して、おそらく大丈夫だと思います <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/FrameLayout01" android:layout_height="match_parent" android:layout_width="match_parent" android:layout_weight="10" > <Button android:layout_gravity="bottom|right" android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/trash" android:background="@drawable/custom_button"/> <ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/aaaa" android:src="@drawable/aaa" android:layout_gravity="center" /> </FrameLayout>
- ベストアンサー
- Java