2016-06-27 7 views
1

私はlinearLayout(水平)内に3つのTextViewを持ち、最後のテキストビューが大きすぎるか、スペースがない場合、それは親と一致し、下の画像のようです:私が欲しいものAndroid - 移動しない場合はtextView

Image Here

はTextViewにはのLinearLayoutの幅に達した場合、その後、TextViewには、「プロパティ」のTextViewの下に移動させなければならないことです。 (次の行)

はそれがどうあるべきかを見てみましょう:私のXMLの抜粋です

Image here

:事前xの

<LinearLayout 
       android:orientation="horizontal" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginTop="5dp"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearance" 
        android:text="Property" 
        android:id="@+id/txtPropertyType" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearance" 
        android:text="/ 127 m" 
        android:id="@+id/txtArea" 
        android:layout_marginLeft="10dp" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearance" 
        android:text="/ 3 roomsssssssssdddd" 
        android:singleLine="false" 
        android:id="@+id/txtNumRoom" 
        android:layout_marginLeft="5dp" /> 
      </LinearLayout> 

おかげで)

答えて

0

は、XMLを変更し、のLinearLayout、下記の別のTextViewを追加します。

OPTION 1:部屋番号のTextViewの長さを確認してください

 <LinearLayout 

      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="5dp"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearance" 
       android:text="Property" 
       android:id="@+id/txtPropertyType" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearance" 
       android:text="/ 127 m" 
       android:id="@+id/txtArea" 
       android:layout_marginLeft="10dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearance" 
       android:text="/ 3 roomsssssssssdddd" 
       android:singleLine="false" 
       android:id="@+id/txtNumRoom" 
       android:layout_marginLeft="5dp" /> 
     </LinearLayout> 

     <TextView 
      android:visibility="gone" 
      android:layout_below="@+id/linearLayout" 
      android:id="@+id/long_room" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="dfgdfdfgddfgdfgdd"/> 

、あなたは2つのオプションがあります。たとえば、12よりも大きければ(wのように、すべての文字が最も幅が広いと考えられる数を見つけなければならない)、txtNumRoomの可視性とlong_roomの可視性を表示します。

オプション2:txtNumRoomがレンダリングされて表示される前にその高さを見つけます。この高さがtxtAreaの高さより大きい場合、これはテキストビューが複数行になったことを意味します。この場合にも、この場合には、可視性をtxtNumRoomGONE、long_roomを表示します。 レンダリングされる前に、テキストビューの高さをプログラムで見つける方法を知るには、this questionを参照してください。

+0

それは働いた!私はadapter.notifyDataSetChanged()をする必要があった。私のリストビューでは、それは働いた:Dありがとう! –

0

だけ各テキストビューでandroid:singleLine = "true"を追加します。あなたの問題は、TextViewが複数の行に広がっていることです。

+0

私はsingleLineをtrueに設定すると、適合しないときには省略されます。私はそれを望みません。 –

関連する問題