0

I just want to show vertically a title, a picture, a description but instead I got all text controls above the picture whereas I did specify a vertical layout (android:orientation="vertical") in fragment showed by ViewPager :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity$DummySectionFragment" >

        <TextView
        android:id="@+id/section"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

        <ImageView 
        android:id="@+id/image"
        android:src="@drawable/image1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

        <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
user310291
  • 36,946
  • 82
  • 271
  • 487

4 Answers4

2

android:orientation="vertical" is for LinearLayout, change this to a LinearLayout or if you want to use a RelativeLayout define exactly where views are supposed to be displayed relative to other views. More info here: What are the differences between LinearLayout, RelativeLayout, and AbsoluteLayout?

Community
  • 1
  • 1
VM4
  • 6,321
  • 5
  • 37
  • 51
1

use LinearLayout instead of RelativeLayout or just implement Eng. Samer T solution

xgc1986
  • 868
  • 6
  • 8
1

You are using relativelayout

In relative layout no matter with orientation

Just use below snippet

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity$DummySectionFragment" >

    <TextView
        android:id="@+id/section"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="section" />

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="description" />

</LinearLayout>
Tulsiram Rathod
  • 1,926
  • 2
  • 19
  • 29
0

    <TextView
    android:id="@+id/section"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

    <ImageView 
    android:id="@+id/image"
    android:src="@drawable/image1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/section"
    />

    <TextView
    android:id="@+id/description"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/image"       />

Eng. Samer T
  • 6,465
  • 6
  • 36
  • 43