Reputation: 15
My xml layout design is not what it is supposed to be from my code. I am not changing anything dynamically.
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp"/>
<TextView
android:id="@+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/rollnoT"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp"/>
<TextView
android:id="@+id/cmtT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="@android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
My design:
Look at "abc" It should be below '5' not in mid.
I have set android:layout_below="@+id/rollnoT"
but still it is shown in mid.
Pls help me solve this issue.
Upvotes: 1
Views: 83
Reputation: 2067
Try this blow snippet,
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp" />
<TextView
android:id="@+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/rollnoT"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp" />
</LinearLayout>
<TextView
android:id="@+id/cmtT"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="@android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
It would be great if you have practice about LinearLayout
. It solves lots of issues. If you are using RelativeLayout
then it is dependable on other views.
Upvotes: 0
Reputation: 635
Try this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/rollnoT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="5"
android:textSize="200sp"/>
<TextView
android:id="@+id/nameT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/rollnoT"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="abc"
android:textSize="30sp"/>
<TextView
android:id="@+id/cmtT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:alpha="0"
android:background="@android:color/holo_red_light"
android:gravity="center_vertical|center_horizontal"
android:text="Ab"
android:textSize="200sp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
Upvotes: 1