TextViews不允许RelativeLayout的正确对齐

TextViews不允许RelativeLayout的正确对齐

本文介绍了TextViews不允许RelativeLayout的正确对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView(uploaderTv)应排队下面titleTv与viewCountTv到它的权利。问题是titleTv有时会重叠成第二行 - 并导致与它下面的文字重叠(看字下面蕾哈娜 - 你可以勉强看到uploaderTv的TextView)。

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).

<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。

我想了textViews出现(正确一字排开,没有重叠或隐藏),因为他们在这里做的:

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

推荐答案

你怎么会知道在哪里放置#X意见部分?我的意思是,视频的创作者可能是ABC,它可能是ABCDEFG甚至有可能会很长,甚至采取单行(特别是对于小屏幕)。

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).

反正,你可以做什么,要么是使用单一的TextView(和可能使用的为了设置它的一部分是灰色的),或者使用类似的(通过的应用程序)。

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).

这篇关于TextViews不允许RelativeLayout的正确对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:19