0

I have a textview (uploaderTv) which should be lined up below titleTv with viewCountTv to the right of it. The problem is the titleTv sometimes overlaps into a second line - and causes an overlap with the text below it (look below the word Rihanna - you can barely see the uploaderTv textView).

Screenshot:

enter image description here

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    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:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtubeplayerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <com.pagesuite.flowtext.FlowTextView
        android:id="@+id/tv"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/titleTv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:paddingLeft="5dp"
            android:text=""
            android:textSize="20sp" />

        <TextView
            android:id="@+id/uploaderTv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/titleTv"
            android:paddingLeft="5dip"
            android:paddingTop="40dp"
            android:textColor="@color/verylightgrey"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/viewCountTv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/uploaderTv"
            android:paddingTop="40dp"
            android:textColor="@android:color/black"
            android:textSize="16sp" />

        <ImageView
            android:id="@+id/buyButton"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:layout_gravity="right"
            android:src="@drawable/buy_a_up_btn" />
    </com.pagesuite.flowtext.FlowTextView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/verylightgrey"
            android:orientation="vertical"
            android:paddingBottom="8dip"
            android:paddingLeft="8dip"
            android:paddingRight="8dip"
            android:paddingTop="13dip" >

            <EditText
                android:id="@+id/editText1"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_weight="1"
                android:background="@color/white"
                android:ems="10"
                android:hint="Post Comment" >

                <requestFocus />
            </EditText>

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/editText1"
                android:layout_alignBottom="@+id/editText1"
                android:layout_alignParentRight="true"
                android:background="@color/black"
                android:text="SEND"
                android:textColor="@color/verylightgrey" />
        </RelativeLayout>

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:paddingBottom="4dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp"
            android:text=""
            android:textColor="@color/grey"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/name"
            android:layout_weight="1"
            android:gravity="left"
            android:paddingBottom="4dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp"
            android:text=""
            android:textColor="@color/lightgrey"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/published"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/content"
            android:layout_weight="1"
            android:gravity="left"
            android:paddingBottom="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp"
            android:text=""
            android:textColor="@color/verylightgrey"
            android:textSize="16sp" />
    </LinearLayout>

</LinearLayout>

P.S.

I'd like the textViews to appear (lined up correctly, not overlapping or hidden) as they do here:

enter image description here

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Droidzilla
  • 137
  • 3
  • 16

2 Answers2

0

how would you know where to put the #X views part? i mean, the creator of the video could be "abc" and it could be "abcdefg" it could even be very long to even take a single row (especially for small screens).

anyway, what you could do is either using a single textView (and probably use fromHtml in order to set a part of it to be gray) or use something like this solution (found via devAppsDirect app).

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • I was able to achieve this: http://i.stack.imgur.com/7ZMaF.png Using the source here: http://pastebin.com/Zvk4Vejm Are you sure I can't replicate something like this without using an external JAR? I'll use it if necessary - I just think there should be a way to do it in my player.xml like I did in my home.xml – Droidzilla Dec 19 '13 at 21:32
  • i just don't know what you try to do. you wish to have 2 texts, and after one ends, put another but with a different style/color ? if so, you can use the first solution i've written (check this out: https://www.grokkingandroid.com/android-quick-tip-formatting-text-with-html-fromhtml/ ). if not, the second solution is ok too. it depends on what you want to do. – android developer Dec 19 '13 at 21:35
  • another solution is to use spans , for example this one: http://stackoverflow.com/questions/3282940/set-color-of-textview-span-in-android – android developer Dec 19 '13 at 21:38
  • I just used flowtextview (updated my source above) and it still appears exactly the same - are there some parameters I should remove before it will work? – Droidzilla Dec 19 '13 at 21:40
  • please first try the other solutions i've written about which don't require any libraries. – android developer Dec 19 '13 at 21:42
  • Ok - I'll give em a whirl! thanks for your help! (on this and my other question you've responded to) – Droidzilla Dec 19 '13 at 21:46
  • ok, please post your code in case you've succeeded ,so that others could learn too. also show it in case you didn't , so that i could check it out and tell you what's wrong. – android developer Dec 19 '13 at 21:56
  • No prob - I posted what I found to fix it (the only issues I'm really concerned with at this point is why my onClick listener won't even launch a toast (it's quite bizarre) http://stackoverflow.com/questions/20685907/onclick-listener-on-drawerlayout-does-not-launch-toast and this SUPER simple issue: it's 99.99% functional - I just need to expand it beyond one swipe in each direction - http://stackoverflow.com/questions/20690231/expanding-viewpager-position-values-beyond-one-swipe-left-and-one-swipe-right – Droidzilla Dec 19 '13 at 22:06
  • I'm still having trouble getting text to wrap properly so I'm using the library you suggested - do you know how to increase the font size? http://stackoverflow.com/questions/20706534/setting-text-size-using-flowtextview-java-android-xml – Droidzilla Dec 20 '13 at 15:20
-1

I was able to resolve the issue by using the following:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    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:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtubeplayerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/titleTv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:paddingLeft="5dp"
            android:text=""
            android:textSize="20sp" />

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

            android:layout_below="@+id/titleTv"
            android:paddingLeft="5dip"
            android:paddingTop="5dp"
            android:textColor="@color/verylightgrey"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/viewCountTv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/uploaderTv"
            android:layout_below="@+id/titleTv"
            android:paddingTop="5dp"
            android:textColor="@android:color/black"
            android:textSize="16sp" />

        <ImageView
            android:id="@+id/buyButton"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"

            android:layout_centerVertical="true"
            android:src="@drawable/buy_a_up_btn" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/verylightgrey"
            android:orientation="vertical"
            android:paddingBottom="8dip"
            android:paddingLeft="8dip"
            android:paddingRight="8dip"
            android:paddingTop="13dip" >

            <EditText
                android:id="@+id/editText1"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_weight="1"
                android:background="@color/white"
                android:ems="10"
                android:hint="Post Comment" >

                <requestFocus />
            </EditText>

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/editText1"
                android:layout_alignBottom="@+id/editText1"
                android:layout_alignParentRight="true"
                android:background="@color/black"
                android:text="SEND"
                android:textColor="@color/verylightgrey" />
        </RelativeLayout>

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:paddingBottom="4dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp"
            android:text=""
            android:textColor="@color/grey"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/content"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/name"
            android:layout_weight="1"
            android:gravity="left"
            android:paddingBottom="4dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp"
            android:text=""
            android:textColor="@color/lightgrey"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/published"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/content"
            android:layout_weight="1"
            android:gravity="left"
            android:paddingBottom="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp"
            android:text=""
            android:textColor="@color/verylightgrey"
            android:textSize="16sp" />
    </LinearLayout>

</LinearLayout>
Droidzilla
  • 137
  • 3
  • 16