androidアプリ開発でxmlファイルを使いレイアウトを定義しているのですが、画像とテキスト・ボタンを縦に並べる方法がわからないので教えてください。
実現したい内容は以下です。
・画面上部に画像を表示し、その下にボタンを横一列で表示する。
以下のようなXMLを書くと、画面上部で画像とボタンが重なって表示されます。
xml
1<RelativeLayout 2 android:layout_width="fill_parent" 3 android:layout_height="fill_parent" 4 xmlns:android="http://schemas.android.com/apk/res/android" 5 android:orientation="vertical"> 6 7 <ImageView 8 android:id="@+id/imageview" 9 android:layout_width="match_parent" 10 android:layout_height="match_parent" 11 android:src="@drawable/logo" 12 android:scaleType="fitStart" 13 android:contentDescription="ロゴ画像" 14 /> 15 16 <LinearLayout 17 android:id="@+id/layout_root" 18 android:layout_width="fill_parent" 19 android:layout_height="fill_parent" 20 xmlns:android="http://schemas.android.com/apk/res/android" 21 android:orientation="vertical" 22 android:layout_alignParentBottom="true"> 23 <Button 24 android:id="@+id/to_login_button" 25 android:layout_width="wrap_content" 26 android:layout_height="wrap_content" 27 android:layout_gravity="bottom" 28 android:text="ログイン" 29 android:textColor="#ffffff" 30 android:layout_centerVertical="true" 31 android:layout_alignParentLeft="true" 32 android:layout_alignParentStart="true"/> 33 34 <Button 35 android:id="@+id/to_register_button" 36 android:layout_width="wrap_content" 37 android:layout_height="wrap_content" 38 android:layout_gravity="bottom" 39 android:text="新規登録" 40 android:textColor="#ffffff" 41 android:layout_alignTop="@+id/to_login_button" 42 android:layout_alignParentRight="true" 43 android:layout_alignParentEnd="true"/> 44 45 </LinearLayout> 46</RelativeLayout>
また、「ボタン」、「テキスト」のみだとLinearLayoutを使えば並べて表示できるのですが、
同じやり方で「画像」を表示しようとすると画像がだけ前面に表示されてしまいます。
画像とボタン、テキストを組み合わせて画面に表示したい場合、
どのようなレイアウトの仕方があるのでしょうか?
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。