Reputation: 9
I am trying to place my textview4
below, my sourceNameTextView
, but i can't see the text from textView4
? I am new to using relative layout can someone tell me why this is happening and how to fix this? I already tried reading some post on stackoverflow but can't find anything that fixes this issue.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_marginLeft="18dp"
android:layout_marginRight="18dp"
android:layout_marginBottom="18dp"
android:background="@drawable/gradient"
android:clickable="true"
android:focusable="true"
android:padding="6dip">
<ImageView
android:id="@+id/newsThumbnail"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:contentDescription="TODO"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/newsBody"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_above="@id/sourceName"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/newsThumbnail"
android:gravity="center_vertical"
android:textColor="#FFFFFF"
android:textSize="16sp" />
<TextView
android:id="@+id/sourceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_toEndOf="@id/newsThumbnail"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Description"
android:textColor="#9A9CA5"
android:textSize="12sp" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_toEndOf="@id/newsThumbnail"
android:layout_below="@+id/sourceName"
android:layout_height="wrap_content"
android:text="TextViwew.." />
</RelativeLayout>
Upvotes: 0
Views: 54
Reputation: 1716
EDIT: Also like Zain said, you had alignParentBottom which caused the view to push your layout out of the view. Try to avoid fixed height if you don't really have to use it. But either way, I think that using LinearLayout
would make your life much easier and in the future it will be easier to edit the code.
You can't see the TextView
because you set a fixed height on your RelativeLayout
. Other layouts take too much space and because of that your TextView
is below sourceName
but not visible as it's out of the layout.
To change this you can add wrap_content
as height for your RelativeLayout
. Then you'll have to play a lot with layout attributes to get what you want. What you are trying to achieve is way easier if you just use LinearLayout
for the right part of your layout. Like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginRight="18dp"
android:layout_marginBottom="18dp"
android:clickable="true"
android:focusable="true"
android:padding="6dip">
<ImageView
android:id="@+id/newsThumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginEnd="6dip"
android:contentDescription="TODO"
android:src="@mipmap/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/newsThumbnail"
android:orientation="vertical">
<TextView
android:id="@+id/newsBody"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:text="NEWS BODY"
android:textSize="16sp" />
<TextView
android:id="@+id/sourceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Description"
android:textColor="#9A9CA5"
android:textSize="12sp" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextViwew.." />
</LinearLayout>
</RelativeLayout>
The result for this:
Upvotes: 1
Reputation: 40908
The reason you don't see textView4
because you added android:layout_alignParentBottom="true"
to the sourceName
TextView
,
This means that that you want to align a view which is textView4
to be beneath of a View that is exactly at the bottom of the parent.
So, the textView4
will be off the screen or correctly speaking will be off the RelativeLayout
(under the bottom of it)
To Solve this You need to remove android:layout_alignParentBottom="true"
from the sourceName
TextView
Also when you do this change you will notice that newsBody
now is gone, that is because you added android:layout_above="@id/sourceName"
to it and didn't constraint the sourceName
to be at the bottom of it.
You can use now:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginLeft="18dp"
android:layout_marginRight="18dp"
android:layout_marginBottom="18dp"
android:background="@drawable/gradient"
android:clickable="true"
android:focusable="true"
android:padding="6dip">
<ImageView
android:id="@+id/newsThumbnail"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:contentDescription="TODO"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/newsBody"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toEndOf="@id/newsThumbnail"
android:layout_toRightOf="@id/newsThumbnail"
android:gravity="center_vertical"
android:textColor="#FFFFFF"
android:textSize="16sp" />
<TextView
android:id="@+id/sourceName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="@+id/newsBody"
android:layout_marginBottom="10dp"
android:layout_toEndOf="@id/newsThumbnail"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Description"
android:textColor="#9A9CA5"
android:textSize="12sp" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/sourceName"
android:layout_toEndOf="@id/newsThumbnail"
android:layout_toRightOf="@id/newsThumbnail"
android:text="TextViwew.." />
</RelativeLayout>
Upvotes: 1