I use this layout as a dialog. The problem is that the button appears to the right of the text.I tried with padding,position,gravity to make it appear UNDER the textview but I failed.
Hope you can help me….
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
<Button
android:id="@+id/ok"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="ok"
/>
</LinearLayout>
You’re using a
LinearLayoutin a horizontal orientation. That means it will list all views in a row horizontally in the order you put them.You obviously want the image next to the text, so there are two ways to do that. You can use two
LinearLayouts. The top one in a vertical orientation and the inner in a horizontal. The inner will contain the image and text. The outer will contain the inner and the button.The second is to use
RelativeLayoutwhich allows you to set attributes likelayout_belowwhich will place the button below the text no matter where you put the text.With two LinearLayouts:
With RelativeLayout (simpler):