2015-10-16 57 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>