2015-10-16 26 views
0

我有一個「TextView」的問題,我不知道如何解決。我在「LinearLayout」中有三個「TextView」,並且文本將保持與斷線相同的大小。目前,文本是在同一行上,但大小不同。該怎麼辦?下面的圖像和代碼:Android:如何並排修復TextView?

<LinearLayout 
      android:id="@+id/complementaryInfoLayout" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:layout_width="match_parent" 
      android:orientation="horizontal" 
      android:background="@color/purewhite"> 


      <TextView 
       android:id="@+id/textCategory" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:textColor="#545454" 
       android:layout_marginStart="15dp"    
       android:text="@string/placeholder" /> 

      <TextView 
       android:id="@+id/textCity" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:textColor="#545454" 
       android:text="@string/placeholder" /> 

      <TextView 
       android:id="@+id/textNeighborhood" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="18sp" 
       android:textColor="#545454" 
       android:text="@string/placeholder" /> 

     </LinearLayout> 

How is the tablet

回答

0

嗯..最後一行似乎被打破二人字符串大小。 您可以預留的TextView佔據一行,無論其內容使用:

android:singleLine="true"

此外,你還可以通過提供一個很好的接觸:

android:ellipsize="marquee"

所以它不會裁剪突然在內容它。

希望它可以幫助...

0

先給權重的TextView S:

 <LinearLayout 
     android:id="@+id/complementaryInfoLayout" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:background="@color/purewhite"> 


     <TextView 
      android:id="@+id/textCategory" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" 
      android:textColor="#545454" 
      android:layout_marginStart="15dp"    
      android:text="@string/placeholder" /> 

     <TextView 
      android:id="@+id/textCity" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" 
      android:textColor="#545454" 
      android:text="@string/placeholder" /> 

     <TextView 
      android:id="@+id/textNeighborhood" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" 
      android:textColor="#545454" 
      android:text="@string/placeholder" /> 

    </LinearLayout> 
0

需要您的查詢比較清楚,我希望你要調整水平線性佈局3個孩子的,對於這

可以使用android:layout_weight屬性,在下面的代碼我已經使用layout_weight2, 3 and 5 respectiviely,

這裏2+3+5=10total 10 parts equal to 100% width

所以第一TextView的佔用(2/10)*100 = 20% width horiontally

所以第二TextView的佔據(3/10)*100 = 30%寬度horiontally

所以第三TextView的佔用(5/10)*100 = 50% width horiontally

<LinearLayout 
       android:id="@+id/complementaryInfoLayout" 
       android:layout_height="wrap_content" 
       android:layout_width="match_parent" 
       android:orientation="horizontal" 
       android:background="@color/purewhite"> 
       <TextView 
       android:id="@+id/textCategory" 
       android:layout_width="0dp" 
       android:layout_weight="2" 
       android:layout_height="wrap_content"/> 
      <TextView 
       android:id="@+id/textCity" 
       android:layout_width="0dp" 
       android:layout_weight="3" 
       android:layout_height="wrap_content"/> 
      <TextView 
       android:id="@+id/textNeighborhood" 
       android:layout_width="0dp" 
       android:layout_weight="5" 
       android:layout_height="wrap_content"/> 
</LinearLayout>