2013-08-30 36 views
0

我有两个TextView的。当第一个太长时,第二个消失。我已经尝试RelativeLayout与android:layout_alignParentRight="true",但它并不真的为我工作。当第一个TextView太长,第二个disapper

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="@dimen/list_margin" 
     android:text="@string/movie_title" 
     android:textColor="#FFFFFF" 
     android:textSize="22sp" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_toRightOf="@+id/textView1" 
     android:layout_marginLeft="@dimen/list_margin" 
     android:text="@string/new_sounds" 
     android:textColor="#8C1717" 
     android:textSize="13sp" 
    android:visibility="1"/> 

</RelativeLayout> 

这将是单行ListView中,其中第一TextView的是电影的标题,有时会出现另一个文本可见的布局。但是,正如我所说,当电影标题很长时,屏幕上看不到textView2。我该怎么做才能让它在第一个结束的地方(例如它结束于第二行,然后是textView2

+0

变化的android:layout_width = “WRAP_CONTENT” 到match_parent(均为textViews),然后加入Android:layout_alignParentLeft = “true” 以textView1。这应该做的伎俩。如果它起作用,就写。 –

+0

不是。总而言之,我用'android:layout_weight'制作了LinearLayout。这不是我想要的,但它工作正常。 – Roval

回答

0

您已使用android:layout_width="wrap_content",这会使文本视图变为只要它里面的文字。您可以将其更改为android:layout_width="match_parent"或特定宽度,然后将其限制为指定的任何内容。

+0

这已经在答案的评论中。 –

+0

@ divoom12我发布后发现。我没有刷新页面。 – mou

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="@dimen/list_margin" 
    android:layout_weight="1" 
    android:text="@string/movie_title" 
    android:textColor="#FFFFFF" 
    android:textSize="22sp" /> 

<TextView 
    android:id="@+id/textView2" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="@dimen/list_margin" 
    android:layout_weight="1" 
    android:text="@string/new_sounds" 
    android:textColor="#8C1717" 
    android:textSize="13sp" /> 

</LinearLayout> 
0

,你只需要设置android:layout_weight="1"每个TextView的,那么它们可以共享

相关问题