Reputation: 1
I am posting my code please help me.I am using relative layout with vertical orientation.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="@+id/next"
android:layout_marginTop="170dp"
android:layout_alignParentRight="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous"
android:id="@+id/previous"
android:layout_marginTop="170dp"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/day"
android:textStyle="bold"
android:textSize="30dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>
<ImageView
android:id="@+id/product_image"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_marginTop="-50dp"/>
<TextView
android:id="@+id/description"
android:text="test"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18dp"
android:layout_below="@id/product_image"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"/>
Upvotes: 0
Views: 1140
Reputation: 5609
In relative layouts, all views should have at least one anchor. Your image view doesn't have any. Neither does the day view. They can anchor to each other or to the parent view. If you don't specify it acts just like a frame view and will anchor to the upper left. Try not to rely on margins for layout, but rather for padding between the views - and negative margins are generally a really bad idea.
Try something like this:
<TextView
android:id="@+id/day"
android:textStyle="bold"
android:textSize="30dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"/>
<ImageView
android:id="@+id/product_image"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@id/day"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/description"
android:text="test"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18dp"
android:layout_below="@id/product_image"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="@+id/next"
android:layout_below="@id/description"
android:align_parentBottom="true"
android:layout_alignParentRight="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previous"
android:id="@+id/previous"
android:layout_below="@id/description"
android:align_parentBottom="true"
android:layout_alignParentLeft="true" />
Upvotes: 1