2015-10-13 168 views
0

我在设置布局时遇到了一些问题,问题在于用户生物的文本可能会有所不同,但使其textview高度是tvbio在下面的代码中wrap_content添加填充顶部,所以有效地干扰所有的布局,这里是我的xml设置textview的高度添加填充顶部

<LinearLayout 
      android:id="@+id/userInfoHeadrLL" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:paddingLeft="5dip" 
      android:paddingRight="10dip" 
      android:paddingTop="0dip" > 

      <RelativeLayout 
       android:id="@+id/userInfoRL" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:layout_marginTop="-50dip" 
       android:orientation="vertical" > 

       <ImageView 
        android:id="@+id/IVProfilePicture" 
        android:layout_width="120dp" 
        android:layout_height="120dip" 
        android:layout_alignParentStart="true" 
        android:layout_centerVertical="true" 
        android:background="@null" 
        android:paddingRight="6dip" 
        android:src="@drawable/anonymous_user" /> 

       <TextView 
        android:id="@+id/TVAmountEarned" 
        style="@style/small_body_text" 
        android:layout_width="wrap_content" 
        android:layout_height="40dip" 
        android:layout_below="@+id/IVProfilePicture" 
        android:layout_marginLeft="42dip" 
        android:gravity="center" 
        android:text="$0.00" 
        android:textColor="@color/grey" /> 

       <TextView 
        android:id="@+id/TVHolder" 
        style="@style/small_body_text" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/TVFullName" 
        android:layout_toRightOf="@+id/IVProfilePicture" 
        android:paddingBottom="-5dip" 
        android:text="samjaved" 
        android:textColor="@color/blue" /> 

       <TextView 
        android:id="@+id/TVFullName" 
        style="@style/small_body_text" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/simpleViewAboveTable" 
        android:layout_toRightOf="@+id/IVProfilePicture" 
        android:paddingBottom="0dip" 
        android:text="sami" 
        android:textColor="@color/grey" /> 

       <View 
        android:id="@+id/simpleViewAboveTable" 
        android:layout_width="fill_parent" 
        android:layout_height="1dp" 
        android:layout_above="@+id/tableUserInfoFollow" 
        android:layout_toRightOf="@+id/IVProfilePicture" 
        android:background="@color/llgrey" /> 

       <TableLayout 
        android:id="@+id/tableUserInfoFollow" 
        android:layout_width="fill_parent" 
        android:layout_height="45dip" 
        android:layout_centerVertical="true" 
        android:layout_marginBottom="2dip" 
        android:layout_toRightOf="@+id/IVProfilePicture" 
        android:stretchColumns="*" > 

        <TableRow 
         android:layout_width="wrap_content" 
         android:layout_height="45dip" > 

         <LinearLayout 
          android:layout_width="50dp" 
          android:layout_height="wrap_content" 
          android:layout_alignParentLeft="true" 
          android:layout_marginTop="8dip" 
          android:gravity="center" 
          android:orientation="vertical" > 

          <TextView 
           android:id="@+id/textPostedCount" 
           style="@style/small_body_text" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:text="0" /> 

          <TextView 
           android:id="@+id/tvPosted" 
           style="@style/small_body_text" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginTop="-8dip" 
           android:text="Posted" /> 
         </LinearLayout> 

         <LinearLayout 
          android:layout_width="50dp" 
          android:layout_height="wrap_content" 
          android:layout_alignParentLeft="true" 
          android:layout_marginTop="8dip" 
          android:gravity="center" 
          android:orientation="vertical" > 

          <TextView 
           android:id="@+id/textFollowersCount" 
           style="@style/small_body_text" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:text="0" /> 

          <TextView 
           android:id="@+id/tvFollower" 
           style="@style/small_body_text" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginTop="-8dip" 
           android:text="Followers" /> 
         </LinearLayout> 

         <LinearLayout 
          android:layout_width="50dp" 
          android:layout_height="wrap_content" 
          android:layout_alignParentLeft="true" 
          android:layout_marginTop="8dip" 
          android:gravity="center" 
          android:orientation="vertical" > 

          <TextView 
           android:id="@+id/textFollowedCount" 
           style="@style/small_body_text" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:gravity="center_vertical" 
           android:text="0" /> 

          <TextView 
           android:id="@+id/tvFollowed" 
           style="@style/small_body_text" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:layout_marginTop="-8dip" 
           android:gravity="center_vertical" 
           android:text="Followed" /> 
         </LinearLayout> 
        </TableRow> 
       </TableLayout> 

       <View 
        android:id="@+id/simpleViewBelowLayout" 
        android:layout_width="fill_parent" 
        android:layout_height="1dp" 
        android:layout_below="@+id/tableUserInfoFollow" 
        android:layout_toRightOf="@+id/IVProfilePicture" 
        android:background="@color/llgrey" /> 

       <TextView 
        android:id="@+id/TVbio" 
        style="@style/small_body_text" 
        android:layout_width="fill_parent" 
        android:layout_height="200dip" 
        android:layout_below="@+id/simpleViewBelowLayout" 
        android:layout_marginTop="2dp" 
        android:layout_toRightOf="@+id/IVProfilePicture" 
        android:paddingBottom="0dip" 
        android:text="bio will go here sahsakjhdjahdjhdjhdjsahdjhahahdjhdsjhdajhdsjhdskjhakjhdskjashjkasjk" /> 
      </RelativeLayout> 
     </LinearLayout> 

为了解决这个问题,我目前检查代码中的生物的文本和相应的设置高度和利润,但似乎不喜欢,因为它的最好办法在不同的屏幕上显示不同的结果,在这方面的任何帮助将不胜感激。

编辑

And this is how it should show when there is text at bottom 1是没有文字

第二是所需的行为应该如何表现时,有文字在底部

第三是如何被它目前呈现当没有文字时,请注意$ 0.00以下的额外空间

如何摆脱多余的空间?

如果要实现这一点,我减少了textview的高度,在较大的文本开始剪裁时会出现问题。

+0

你可以用截图显示吗? –

+0

您可以使用属性“paddingTop”来减少TextView的填充。 – NoChinDeluxe

+0

@drschultz我实际上不知道应该设置多少paddingtop,因为textview的高度根据文本的不同而不同 –

回答

0

我认为设置android:layout_height="wrap_content"绝对是您的TVBio TextView的方式。您当然希望视图的大小根据您将收到的各种文本的大小而定。所以我认为那部分是对的。

但是,如果您的文本在使用该属性时被切断,我会尝试设置android:layout_gravity="fill"。该属性告诉父级如何将子视图放置在容器内。我会开始尝试fill,如果这不起作用,你可以尝试一些其他的。你可以找到一个all possible settings here的列表。

+0

此外,您可以尝试在文本末尾添加几个'\ n'字符,以强制视图的大小比实际文本内容稍大。 – NoChinDeluxe