2015-10-13 178 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